弃用 jQuery.ajax 中的成功参数? [英] Deprecation of success Parameter in jQuery.ajax?

查看:36
本文介绍了弃用 jQuery.ajax 中的成功参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天听说jQuery.ajax 函数中的success-Parameter 被弃用了.我理解正确吗?还是我误会了什么?

Today I have heard that the success-Parameter in the jQuery.ajax function is deprecated. Have I understood that correctly? Or am i missunderstanding something?

例如,这在未来将不起作用:

For Example this would not work in the future:

 $.ajax({

            url: 'ax_comment.php',              
            type: 'POST',
            data: 'mode=view&note_id='+noteid+'&open='+open+'&hash='+hash,
            success: function(a) {
            ...

            }   

    });

我必须使用这个吗?

$.ajax({

            url: 'ax_comment.php',

            type: 'POST',
            data: 'mode=view&note_id='+noteid+'&open='+open+'&hash='+hash,
            success: function(a) {
            ...

            }   

    }).done(function(a){.....};

来源:http://api.jquery.com/jQuery.ajax/ (向下滚动到弃用通知)

Source: http://api.jquery.com/jQuery.ajax/ (Scroll down to Deprecation Notice)

推荐答案

有区别,Ajax成功回调方法:

There is a difference between, the Ajax success callback method:

$.ajax({}).success(function(){...});

和 Ajax 成功本地回调事件(即 Ajax 参数和属性):

and the Ajax success local callback event (i.e., the Ajax parameter and property):

$.ajax({
    success: function(){...}
});

成功回调方法(第一个示例)已被弃用.但是,成功本地事件(第二个示例)不是.

The success callback method (first example) is being deprecated. However, the success local event (second example) is not.

本地事件是 Ajax 属性(即参数).jQuery 文档进一步解释了 本地事件 是一个回调,您可以在Ajax 请求对象.

Local events are Ajax properties (i.e., parameters). The jQuery docs further explain that the local event is a callback that you can subscribe to within the Ajax request object.

所以将来,您可以执行以下任一操作:

So in future, you may do either:

$.ajax({}).done(function(){...});

$.ajax({
    success: function(){...}
});

这篇关于弃用 jQuery.ajax 中的成功参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆