javascript - jQuery Ajax POST not returning with PHP variable -


i have following function:

$(window).scroll(function() { if(ready && labelstatus && $(window).scrolltop() + $(window).height() > $(document).height() - 100){    $('#bottom2').html(loading);    ready = false;    $.ajax({     url: 'scripts/nearbothome.php',     data: {"currentnumber": botnumber, "usersid": usersid},     type: 'post',     success: function(data) {     botnumber = "<?php echo $uniqueend; ?>";     alert("<?php echo $uniqueend; ?>");     $('#oldposts').append(data);     $('#bottom2').html(bottom);     ready = true;     labelstatus = data;     if (data < 1) {     labelstatus = false;         }     }   });     } }); 

this works fine , intended except setting variable 'botnumber' new value. php variable it's supposed set should returned .php file executed ajax ($uniqueend).

see here:

<?php //open database connection include("../db.php");  //receive value $currnum = $_post['currentnumber']; $uidd = $_post['usersid'];  $results7 = mysql_query("select * `uc_posts` `postinguser` in (select `followers` `uc_users` `id` = $uidd) , id < $currnum order id desc limit 20");  sleep(1);  while ($row = mysql_fetch_array($results7)) { echo '<div class="postfeed2">';     $color='#ababab';     $id = $row['id'];     $page = $row['page'];     $postinguser = $row['postinguser'];     $displayname=mysql_fetch_array(mysql_query("select `display_name` `uc_users` `id` = $postinguser limit 1"));     $username=mysql_fetch_array(mysql_query("select `user_name` `uc_users` `id` = $postinguser limit 1"));     $checkiffav=mysql_fetch_array(mysql_query("select * `uc_posts` find_in_set($uidd,`likedby`) , `id` = $id"));     if ($checkiffav) {     $color='#ff5733';     }     echo '<table><tr><td style="vertical-align: baseline;"><b><img src="blank-user-medium.png" width="50px" height="50px" style="vertical-align: text-top;margin-right: 8px;margin-top: 0px;border: 0px solid #d0d0d0;border-radius: 5px 5px 5px 5px;"></b></td>';     echo '<td style="display: block;word-break: break-word;"><b>' . $displayname[display_name] . '</b>';     echo ' <span style="color:#ababab;">@' . $username[user_name] . '</span>';     echo '<br>' . $page . '';     echo '<br><a href="javascript:void(0)" onclick="javascript:return like(' . $id . ',' . $uidd . ');"><i class="fa fa-heart fa-lg" id="heart' . $id . '" style="margin-top: 5px;color:' . $color . '"></i></a></td></tr></table>';  echo '</div>'; }  $uniqueend2 = mysql_fetch_array(mysql_query("(select * `uc_posts` `postinguser` in (select `followers` `uc_users` `id` = $uidd) , id < $currnum order id desc limit 20) order id asc"));  $uniqueend = $uniqueend2['id'];  echo $uniqueend;  ?> 

i can see echoes: 184. on alert added jquery in order verify nothing there.

i use json have large amount of php/content data returns i'm not sure how fit in or work.

thanks!

ajax doesn't work way. return value of php script @ server send response browser, gets put data parameter of success-callback function. see, id on data , have work it.

try this:

$(window).scroll(function() { if(ready && labelstatus && $(window).scrolltop() + $(window).height() > $(document).height() - 100){    $('#bottom2').html(loading);    ready = false;    $.ajax({     url: 'scripts/nearbothome.php',     data: {"currentnumber": botnumber, "usersid": usersid},     type: 'post',     success: function(data) {     botnumber = data;     alert(data);     $('#oldposts').append(data);     $('#bottom2').html(bottom);     ready = true;     labelstatus = data;     if (data < 1) {     labelstatus = false;         }     }   });     } }); 

after comment:

you can put html in variable instead of outputting immediately. , put html , id array

$html = "<div>"; // add more html variable $html .= "</div>; $returnarray['html'] = $html;  $returnarray['id'] = $uniqueend; 

and in frontend have access indexes in data

$(window).scroll(function() { if(ready && labelstatus && $(window).scrolltop() + $(window).height() > $(document).height() - 100){    $('#bottom2').html(loading);    ready = false;    $.ajax({     url: 'scripts/nearbothome.php',     data: {"currentnumber": botnumber, "usersid": usersid},     type: 'post',     success: function(data) {     botnumber = $data['id'];     alert($data['id']);     $('#oldposts').append($data['id']);     $('#bottom2').html(bottom);     ready = true;     // don't know trying here on     labelstatus = data;      if (data < 1) {     labelstatus = false;         }     }   });     } }); 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -