开发者

abort() triggers Error Undefined in chrome

I use the following code to throttle get requests in race conditions:

        if (currentAjaxRequest !== null) {
            currentAjaxRequest.abort();
        }   
        var query_string = getQuery();
        currentAjaxRequest = $.get(query_string, function(data, textStatus, xhr) {
            if (xhr.status) {开发者_如何学运维  
                currentAjaxRequest = null;
                // do stuff
            }                       
        });

I've noticed that in Chrome that when the abort is called an error pops up in the javascript console:

GET undefined (undefined)

This does not seem to impact the script at all - everything continues to run just fine. Is there anything I should be doing to correct this? Or is this just the way chrome reports an aborted ajax request?

Thanks for your help


You're probably right in thinking it's the way Chrome reports an aborted request. jQuery calls the XMLHttpRequest's abort() method. The recommendation of how this method should be implemented from the W3C can be found here.

Step 6 of this process is "set the error flag to true", so although Chrome thinks there's an error to report it's undefined as the error message hasn't been set inside the request object.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜