javascript global variable not updating and ajax making same request
<pre><code> &lt;script type="text/javascript"&gt;
    // i need app Id and image name from json
    var waypoint;
    var count = 0;
    var number = 0;
    var url = '{{url("/app/next/")}}/' + number;


     $(document).ready(function() {
        loadMore();       

        $(window).scroll(function() {
                $(window).scrollTop() + $(window).height() &gt;     
$(document).height() - 450 &amp;&amp; 0 == count &amp;&amp; (count = 1,loadMore())
            })
     });

     function loadMore(){
        $.getJSON(url, function(jd) {

            jd.forEach(myFunction);

            function myFunction(item, index) {

                var app = '&lt;a href="{{url('/app/')}}/'+item.id+'"/&gt;';

              $('#content').append(app);
               number = item.id;
              if(item.id == 1){
                count = 1;
              }
              else{
              count = 0;
              }
                 }
                return true;
           });
     }

    &lt;/script&gt;
</code></pre>

<p>Here i am looping threw rows from last to first in database with jquery.
my php script is set to give next last element in the row and working fine if i make the request manually.
<a href="http://theviralappcreate.dev/app/next/4" rel="nofollow">http://theviralappcreate.dev/app/next/4</a> will return element number 3.</p>

<p>whenever i scrool down it makes request at : <a href="http://theviralappcreate.dev/app/next/0" rel="nofollow">http://theviralappcreate.dev/app/next/0</a>    and keeps making same request, however i am updating the number variable by number = item.id;</p>