Method POST, Status (canceled) error message

前端 未结 6 1452
北恋
北恋 2021-02-20 04:08

I have the following code which is giving me a Method POST, Status (canceled) error message:

$(document).ready(function() {
    var xhr = false;

           


        
6条回答
  •  攒了一身酷
    2021-02-20 04:43

    I suppose that the problem is very easy. If you call xhr.abort(); then the error callback of $.ajax will be called for the pending request. So you should just ignore such case inside of error callback. So the error handler can be modified to

    error: function(jqXHR, textStatus, errorThrown) {
        var err;
        if (textStatus !== "abort" && errorThrown !== "abort") {
            try {
                err = $.parseJSON(jqXHR.responseText);
                alert(err.Message);
            } catch(e) {
                alert("ERROR:\n" + jqXHR.responseText);
            }
        }
        // aborted requests should be just ignored and no error message be displayed
    }
    

    P.S. Probably another my old answer on the close problem could also interesting for you.

提交回复
热议问题