title: jQuery Ajax POST not returning with PHP variable
body: <p>I have the following function:</p>
  
  <pre><code>$(window).scroll(function() {
  if(ready &amp;&amp; labelstatus &amp;&amp; $(window).scrollTop() + $(window).height() &gt; $(document).height() - 100){
     $('#bottom2').html(loading);
     ready = false;
     $.ajax({
      url: 'scripts/nearbothome.php',
      data: {"currentNumber": botnumber, "usersid": usersid},
      type: 'post',
      success: function(data) {
      botnumber = "&lt;?php echo $uniqueend; ?&gt;";
      alert("&lt;?php echo $uniqueend; ?&gt;");
      $('#oldposts').append(data);
      $('#bottom2').html(bottom);
      ready = true;
      labelstatus = data;
      if (data &lt; 1) {
      labelstatus = false;
          }
      }
    });    
  }
  });
  </code></pre>
  
  <p>This all works fine and does as intended EXCEPT for setting the variable 'botnumber' to a new value. The PHP variable which it's supposed to be set to should be returned by the .php file executed by the Ajax ($uniqueend).</p>
  
  <p>See here:</p>
  
  <pre><code>&lt;?php
  //open a database connection
  include("../db.php");
  
  //receive value
  $currNum = $_POST['currentNumber'];
  $uidd = $_POST['usersid'];
  
  $results7 = mysql_query("SELECT * FROM `uc_posts` WHERE `postinguser` IN (SELECT `followers` FROM `uc_users` WHERE `id` = $uidd) AND id &lt; $currNum ORDER BY id DESC LIMIT 20");
  
  sleep(1);
  
  while ($row = mysql_fetch_array($results7)) {
  echo '&lt;div class="postfeed2"&gt;';
      $color='#ababab';
      $id = $row['id'];
      $page = $row['page'];
      $postinguser = $row['postinguser'];
      $displayname=mysql_fetch_array(mysql_query("SELECT `display_name` FROM `uc_users` WHERE `id` = $postinguser LIMIT 1"));
      $username=mysql_fetch_array(mysql_query("SELECT `user_name` FROM `uc_users` WHERE `id` = $postinguser LIMIT 1"));
      $checkiffav=mysql_fetch_array(mysql_query("SELECT * FROM `uc_posts` WHERE find_in_set($uidd,`likedby`) AND `id` = $id"));
      if ($checkiffav) {
      $color='#FF5733';
      }
      echo '&lt;table&gt;&lt;tr&gt;&lt;td style="vertical-align: baseline;"&gt;&lt;b&gt;&lt;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;"&gt;&lt;/b&gt;&lt;/td&gt;';
      echo '&lt;td style="display: block;word-break: break-word;"&gt;&lt;b&gt;' . $displayname[display_name] . '&lt;/b&gt;';
      echo ' &lt;span style="color:#ababab;"&gt;@' . $username[user_name] . '&lt;/span&gt;';
      echo '&lt;br&gt;' . $page . '';
      echo '&lt;br&gt;&lt;a href="javascript:void(0)" onclick="javascript:return like(' . $id . ',' . $uidd . ');"&gt;&lt;i class="fa fa-heart fa-lg" id="heart' . $id . '" style="margin-top: 5px;color:' . $color . '"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;';
  
  echo '&lt;/div&gt;';
  }
  
  $uniqueend2 = mysql_fetch_array(mysql_query("(SELECT * FROM `uc_posts` WHERE `postinguser` IN (SELECT `followers` FROM `uc_users` WHERE `id` = $uidd) AND id &lt; $currNum ORDER BY id DESC LIMIT 20) ORDER BY id ASC"));
  
  $uniqueend = $uniqueend2['id'];
  
  echo $uniqueend;
  
  ?&gt;
  </code></pre>
  
  <p>I can see that it echoes: 184. However on the alert I added to the jQuery in order to verify nothing is there.</p>
  
  <p>I would use json but I have a large amount of php/content data it returns so I'm not sure how that would fit in or work.</p>
  
  <p>Thanks!</p>