English 中文(简体)
当亚克斯呼吁失败时,为什么 j笑不会引起错误事件
原标题:Why jQuery does not raise error event when an ajax call fails
  • 时间:2011-11-15 09:19:39
  •  标签:
  • jquery
  • ajax

为什么不提出<代码>ror 何时我按照文字执行?

我认为,我登记了错误事件,但没有发射。

c hrome向我展示了NetworkConsole上的错误。

GET http://www.google.com/adfdaf?questback=jQuery15204572567550931126_1321347602706&_=1321348668347 404 (Notborn)

<>strong>javascript:

    $.ajax({
        type: "GET",
        url:  http://google.com/adfdaf?callback=? ,
        dataType: "jsonp",
        success: function (msg) {
            console.log( Custom Domain validated successfully. );
        },
        error: function () {
            console.log( Error occured while validating Custom Domain. );
        }
    });
最佳回答

The jQuery docs for code>.ajax

eror(jqXHR, textStatus, 误差Thrown)

A function to be called if the request fails. The function receives three arguments: The jqXHR (in jQuery 1.4.x, XMLHttpRequest) object, a string describing the type of error that occurred and an optional exception object, if one occurred. Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror". When an HTTP error occurs, errorThrown receives the textual portion of the HTTP status, such as "Not Found" or "Internal Server Error." As of jQuery 1.5, the error setting can accept an array of functions. Each function will be called in turn. Note: This handler is not called for cross-domain script and JSONP requests.

您可使用.getJSON。 例如:

$.getJSON("url?callback=?", function() {
    //Success!
}).error(function() {
    //Error!
});

<><>Edit>/strong>

象这样的景象也赢得了工作。 工作范围似乎是提供<条码>> 日码选择<条码>。

$.ajax({
    type: "GET",
    url:  http://google.com/adfdaf?callback=? ,
    dataType: "jsonp",
    timeout: 5000,
    success: function (msg) {
        console.log( Custom Domain validated successfully. );
    },
    error: function () {
        console.log( Error occured while validating Custom Domain. );
    }
});

显然,这并不理想,但错误的手稿将在5秒后运行。

问题回答




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签