0

I have an function that sends AJAX request. It's working fine. In my getimage.php, I'm getting 1 row at a time base on ID from 0 to last row of ID. on return, var counter is set to ID value. It all works fine. Only I want the counter to reset back to 0 after my request reaches the last row of table so that my ajax request will run infinitely. Please anyone can show me a simple solution.

var lastsrc = null;
        var counter = 0;
        var delay = 0;

    function changeimage(){

        $.ajax({

            url: 'getimage.php',
            type: 'post',
            data: {
                iddata : counter
            },
            dataType: 'json',
            success: function(data){
            var id=data['id'];
            var title=data['title'];
            var path=data['path'];
            var s_d=data['start_date'];
            var e_d=data['expiration_date'];
            var duration=data['duration'];
            var site=data['site'];
                    alert(id);      
            counter = id

            setTimeout(changeimage, 1000);


        }




        });


    };

    changeimage()   
  • Possible duplicate of [Repeat jQuery ajax call](http://stackoverflow.com/questions/5140939/repeat-jquery-ajax-call) – Jasen Dec 21 '16 at 23:20
  • @Jasen, no. My Ajax Sends request recursively with different data(ID which is in variable counter) Every repeat AJAX request sends a different ID thus my 'getimage.php' file SQL queries with a different condition. variable counter("ID" in getimage.php) increments each request. What I want to accomplish is when my var counter is equivalent to the highest incremented ID in my table, it should reset back to 0 so that my ajax will like run again and query the first row of the table again. – Franz Mile C Dec 22 '16 at 13:36
  • @Jasen, Thanks Anyway. I solved it now. :) – Franz Mile C Dec 22 '16 at 13:56

0 Answers0