javascript - PHP/Ajax/jquery/JSON - Take a part from echo text back as a variable after Ajax Post -


i'm working on simple ajax post method , here code:

     <script type="text/javascript">     jquery(document).ready(function($) {         $(window).scroll(function() {            if($(window).scrolltop() + $(window).height() == $(document).height()) {                  var nexturl = "<?php echo $nexturl;?>";                 $('#loading').show();                 $.ajax({                   url: 'ajax.php',                   type: 'post',                   datatype: 'html',                   data: {                     next_url: nexturl                   },                 }).done(function ( html ) {                   $('#loadedresults').html( html );                   $('#loading').hide();                 });                 }     });     });   </script> 

this code sending post data ajax.php:

<?php  function callinstagram($url)     {     $ch = curl_init();     curl_setopt_array($ch, array(     curlopt_url => $url,     curlopt_returntransfer => true,     curlopt_ssl_verifypeer => false,     curlopt_ssl_verifyhost => 2     ));      $result = curl_exec($ch);     curl_close($ch);     return $result;     }       $client_id = "1e0f576fbdb44e299924a93cace24507";     $next_url = $_post["next_url"];     $url =  $next_url;      $inst_stream = callinstagram($url);     $results = json_decode($inst_stream, true);     $maxid = $results['pagination']['next_max_id'];     $nexturl = $results['pagination']['next_url'];     //now parse through $results array display results...         echo json_encode(array(         'next_url_link' => $nexturl       )); 

the ajax.php echoing result as:

{"next_url_link":"https:\/\/api.instagram.com\/v1\/tags\/sweden\/media\/recent?count=24&client_id=1e0f576fbdb44e299924a93cace24507&max_tag_id=1427904820688670"} 

i looking here , there , think there method json can result of next_url_link.

so guys, how can result printed next_url_link , set active jquery/javascript variable ?

for example:

 var nexturllink = data.next_url_link; 

is possible somehome ? should create 2 .ajax post methods or how, have no idea ?

thanks in advance!

use function json.parse() it. here how :

.done(function ( html ) {                   var data = json.parse(html);                   //now use data.next_url_link                   $('#loadedresults').html(data.next_url_link);                   $('#loading').hide();                 }); 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -