为什么ajax没效果,AJAX成功内部的$(这个)不起作用

问题

在回调内部,this指的是jqXHR对象,而不是事件处理程序绑定到的元素。了解更多关于如何this在JavaScript中工作.

如果ES 2015+对您可用,则使用箭头函数可能是最简单的选择:$.ajax({

//...

success: (json) => {

// `this` refers to whatever `this` refers to outside the function

}});这个对象将成为所有与Ajax相关的回调的上下文。默认情况下,上下文是一个对象,它表示调用中使用的Ajax设置($.ajaxSettings与传递给$.ajax). (...)$.ajax({

//...

context: this,

success: function(json) {

// `this` refers to the value of `context`

}});$.ajax({

//...

success: $.proxy(function(json) {

// `this` refers to the second argument of `$.proxy`

}, this)});

的值的引用。this在回调之外:var element = this;$.ajax({

//...

success: function(json) {

// `this` refers to the jQXHR object

// use `element` to refer to the DOM element

// or `$(element)` to refer to the jQuery object

}});

相关

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值