Jump to content
php.lv forumi
  • 0

JSON masīva atgriezto datu ielikšana mainīgajā


senters

Question

  • Answers 31
  • Created
  • Last Reply

Top Posters For This Question

Recommended Posts

  • 0

Vakarā būs jāprovē šis variants:

 

 

<script>
$.getJSON('sql/insert_comment.php', function(data) {

var masivs = eval('(' + data + ')');
var comment_count =  masivs.all_comments;

});

if (comment_count > 5) { paginate = true; } else { paginate = false; }

$(document).ready(function() {

$('#event_comments').dataTable({
"bPaginate": paginate;
});
});

</script>

 

Kaut gan šādi līdzīgi ar $.getJSON biju mēģinājis, neatgrieza datus.

Edited by senters
Link to comment
Share on other sites

  • 0

Šoreiz jā, jo avots nāk no sava servera. Tīri interesanti palika ko jquery izmanto parsēšanai? Būs jāsaņemas jāpaskatās viņu kods.

 

Vispirms meegjina izmantot saliidzinoshi jaunajaas JS versijaas pieejamo JSON objektu un tad eval ekvivalentu tik elegantaak.

 

parseJSON: function( data ) {
if ( typeof data !== "string" || !data ) {
   	return null;
}
// Make sure leading/trailing whitespace is removed (IE can't handle it)
data = jQuery.trim( data );
// Attempt to parse using the native JSON parser first
if ( window.JSON && window.JSON.parse ) {
   	return window.JSON.parse( data );
}
// Make sure the incoming data is actual JSON
// Logic borrowed from http://json.org/json2.js
if ( rvalidchars.test( data.replace( rvalidescape, "@" )
   	.replace( rvalidtokens, "]" )
   	.replace( rvalidbraces, "")) ) {
   	return ( new Function( "return " + data ) )();
}
jQuery.error( "Invalid JSON: " + data );
}

Edited by rATRIJS
Link to comment
Share on other sites

  • 0

Rakstot šādi nešancē kaut kas:

 

 

<script>
$.getJSON('sql/insert_comment.php', function(data) {
var masivs = eval('(' + data + ')');
var comment_count =  masivs.all_comments;
});

if (comment_count > 5) { paginate = true; } else { paginate = false; }

$(document).ready(function() {
$('#event_comments').dataTable({
"bPaginate": +paginate,
"sPaginationType": "full_numbers",
"bSort": true,
"bFilter": false,
"iDisplayLength": 10,
"bLengthChange": false,
"bInfo": false,
"aaSorting": [[0,'desc']]
});
});
</script>

Edited by senters
Link to comment
Share on other sites

  • 0

Piedomā pie tā, kura koda vieta kurā brīdī izpildās, jo tas kas tev tur ir, neizpildīsies tādā pat secībā, kā tu esi sarakstījis, līdz ar to arī nekas nestrādās tā kā tu esi ieplānojis. Hint: paginate tev tagad vienmēr būs false.

Ja nevari izdomāt, tad saliec katrā rindiņā - console.log('<rindiņas numurs>') un pēc tam konsolē apskaties, var būt, tad kļūs skaidrāks.

Link to comment
Share on other sites

  • 0

Jā, tā būs jādara ar logošanu.

var paginate = false; šādi man ir uzsetots.

 

šādi izskatās pašreizējais kods:

 

 

<script>
$.getJSON('sql/insert_comment.php', function(data) {
var masivs = eval('(' + data + ')');
var comment_count =  masivs.all_comments;
});

var paginate = false;
if (comment_count > 5) { paginate = true; } else { paginate = false; }

$(document).ready(function() {
$('#event_comments').dataTable({
"bPaginate": paginate,
"sPaginationType": "full_numbers",
"bSort": true,
"bFilter": false,
"iDisplayLength": 10,
"bLengthChange": false,
"bInfo": false,
"aaSorting": [[0,'desc']]
});
});
</script>

Edited by senters
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...