senters Posted December 11, 2011 Report Share Posted December 11, 2011 Kā no js funkcijas ajax json masīva (http://screencast.com/t/LheH7PeFp) ielikt datus mainīgajā un izsaukt citā js blokā (http://screencast.com/t/G8HzYcdi1)? Quote Link to comment Share on other sites More sharing options...
0 Grey_Wolf Posted December 12, 2011 Report Share Posted December 12, 2011 (edited) Maris-S -> nu šajā gadījumā tur tiešām nav ko iespringt, piedevām ,nekad jau nezini ko citi var sastrādāt... :( Edited December 12, 2011 by Grey_Wolf Quote Link to comment Share on other sites More sharing options...
0 Maris-S Posted December 12, 2011 Report Share Posted December 12, 2011 Š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. Quote Link to comment Share on other sites More sharing options...
0 senters Posted December 12, 2011 Author Report Share Posted December 12, 2011 (edited) 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 December 12, 2011 by senters Quote Link to comment Share on other sites More sharing options...
0 xPtv45z Posted December 12, 2011 Report Share Posted December 12, 2011 Arī, ja atgriezīs, tad viņš nestrādās, tā kā tev gribētos. Quote Link to comment Share on other sites More sharing options...
0 senters Posted December 12, 2011 Author Report Share Posted December 12, 2011 Tad kas ir tas ko palabot, lai strādātu kā man gribētos? Quote Link to comment Share on other sites More sharing options...
0 rATRIJS Posted December 12, 2011 Report Share Posted December 12, 2011 (edited) Š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 December 12, 2011 by rATRIJS Quote Link to comment Share on other sites More sharing options...
0 senters Posted December 15, 2011 Author Report Share Posted December 15, 2011 (edited) 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 December 15, 2011 by senters Quote Link to comment Share on other sites More sharing options...
0 briedis Posted December 15, 2011 Report Share Posted December 15, 2011 (edited) "bPaginate": +paginate kas tas par +? Muļķīga rindiņa: if (comment_count > 5) { paginate = true; } else { paginate = false; } Normāli būtu šitā: paginate = comment_count > 5; Edited December 15, 2011 by briedis Quote Link to comment Share on other sites More sharing options...
0 senters Posted December 15, 2011 Author Report Share Posted December 15, 2011 paginate mainīgajam jābūt ir true / false, noklusējumā false, ja komentāru skaits lielāks par 5, tad true. Quote Link to comment Share on other sites More sharing options...
0 briedis Posted December 15, 2011 Report Share Posted December 15, 2011 paginate mainīgajam jābūt ir true / false, noklusējumā false, ja komentāru skaits lielāks par 5, tad true. Un kā tev liekas, ar kādu rezultātu izpildās šī izteiksme? "comment_count > 5"? Quote Link to comment Share on other sites More sharing options...
0 senters Posted December 15, 2011 Author Report Share Posted December 15, 2011 Rakstot gan tā kā man bija, gan šādi kā ir tev abos gadījumos neštimmē kaut kas. Quote Link to comment Share on other sites More sharing options...
0 xPtv45z Posted December 15, 2011 Report Share Posted December 15, 2011 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. Quote Link to comment Share on other sites More sharing options...
0 senters Posted December 16, 2011 Author Report Share Posted December 16, 2011 (edited) 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 December 16, 2011 by senters Quote Link to comment Share on other sites More sharing options...
0 xPtv45z Posted December 16, 2011 Report Share Posted December 16, 2011 Ar pašreizējo kodu, viņš tev nekad nebūs true. Quote Link to comment Share on other sites More sharing options...
0 spainis Posted December 16, 2011 Report Share Posted December 16, 2011 Ajax = Asynchronous JavaScript and XML Quote Link to comment Share on other sites More sharing options...
Question
senters
Kā no js funkcijas ajax json masīva (http://screencast.com/t/LheH7PeFp) ielikt datus mainīgajā un izsaukt citā js blokā (http://screencast.com/t/G8HzYcdi1)?
Link to comment
Share on other sites
Top Posters For This Question
11
6
5
4
Popular Days
Dec 12
18
Dec 16
5
Dec 15
5
Dec 11
4
Top Posters For This Question
senters 11 posts
Maris-S 6 posts
briedis 5 posts
Grey_Wolf 4 posts
Popular Days
Dec 12 2011
18 posts
Dec 16 2011
5 posts
Dec 15 2011
5 posts
Dec 11 2011
4 posts
31 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.