简体   繁体   中英

$.ajax, complete function (no more data to get)

Im new to .ajax and so far so good. But I've run into an issue of, I want to run a function once I've used up all the data.

For example I have the following, i run it on 'click':

$.ajax({
        url: "url.modal.tothegoods" + (nextPage),
        success: function (data) {
             //keeps appending data on click
        },
        error: function () {
                alert('balls');
        }

 })

I've tried the ajaxcomplete function but it runs everytime i load data onto the screen.

It runs everytime i appened data .ajaxcomplete runs. I guess the questions is, how do I run a function once I have no more data to consume. So I am truly done

any tips/tricks would be greatly appreciated

The response depends on which is currently the behaviour of your server part.

If you have hand on it, the most simple solution is that it returns nothing when there is no more data to send. So you may do something as simple as this:

$.ajax({
        url: "url.modal.tothegoods" + (nextPage),
        success: function (data) {
             if (!!data) {
             //keeps appending data on click
             }
        },
        error: function () {
                alert('balls');
        }

})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM