English 中文(简体)
j Query AJAX呼救墙上的破例?
原标题:Exceptions thrown in jQuery AJAX callbacks swallowed?

除了增加审判外,还没有任何办法处理美国宇宙航空研究开发厅在 j中发出的呼吁中的例外情况? 在这种情况下,不要求错误功能。

$.ajax(
{
    url:  myurl.rails ,
    success: function( data )
    {
        throw  Oh no! ;
    },
    error: function ( xhr, textStatus, errorThrown )
    {
        console.log(  AJAX call failed , xhr, textStatus, errorThrown );
    }               
} );
最佳回答

如果你看一看一看一栏的粗金字。

function success() {
    // If a local callback was specified, fire it and pass it the data
    if ( s.success ) {
        s.success.call( callbackContext, data, status, xhr );
    }

    // Fire the global callback
    if ( s.global ) {
        trigger( "ajaxSuccess", [xhr, s] );
    }
}

页: 1 仅指<条码>标准/代码”功能适用于环境物体(如果存在的话),而没有任何功能回报或 throw。

您可以做的是:jQuery.ajaxSetup(。 同样:

jQuery.ajaxSetup({
    success: function() {
        try {
            if ( this.mysuccess ) {
                this.mysuccess.apply( this, arguments );
            }
        }
        catch(err) {
            // whatever
        }
    }
});

并使用<条码>。 (或您更愿意称呼)而不是在个人<代码>jQuery.ajax上打字。

问题回答

<代码>eror 呼应,如与请求本身有问题,即予以使用。 The docs:

如果请求失败,就应指定一项职能。 职能有三个论点: XMLHttpRequest 反对, 说明发生错误的类型,以及发生错误的任择例外。 第二种论点(除无效外)的可能价值是“时间外”、“频率”、“未变”和“生产者”。

因此,如果你收回的数据存在问题,那么你应在<条码>中处理(<>条码/代码>退约问题,或许可以将其整理或通知用户。

您是否研究了 j的全球特征,例如





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签