简体   繁体   中英

error using setTimeout with AJAX request

I have the following success method. Before I was using the setTime out it worked without issue but it sent a lot of AJAX requests. To try to slow it down I used setTimeout. Since I put that in I get a bunch of these errors: "Uncaught SyntaxError: Unexpected identifier".

success: function (data) {
    if (data === '') {
        setTimeout( $.ajax(this) ,3000);
        console.log("AJAX resent");

    }
    else {
        //console.log("|", data, "|");
        test.html('');
        test.append(data);
    }
},

The function must be referenced, not evaluated, so if you need to pass parameters, you'll have to wrap it in an anonymous function :

var that = this;
setTimeout(function() {
    $.ajax(that);
} ,3000);

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