Javascript jqueryajax有错误
问题是这行$this.textevalsend.ff_k+1 如果我在ajax之外使用它,这一点都没有问题 $this.text该死 我也有同样的错误 以下是错误: [Error]TypeError:undefined不是计算“a.createDocumentFragment”的对象 db jquery-1.11.1.min.js,第3行 buildFragment jquery-1.11.1.min.js,第3行 domManip jquery-1.11.1.min.js,第3行 追加jquery-1.11.1.min.js,第3行 匿名函数jquery-1.11.1.min.js,第3行 访问jquery-1.11.1.min.js,第3行 文本jquery-1.11.1.min.js,第3行 成功的事实,第192行 jquery-1.11.1.min.js,第2行 fireWith jquery-1.11.1.min.js,第2行 x jquery-1.11.1.min.js,第4行 b jquery-1.11.1.min.js,第4行Javascript jqueryajax有错误,javascript,jquery,ajax,Javascript,Jquery,Ajax,问题是这行$this.textevalsend.ff_k+1 如果我在ajax之外使用它,这一点都没有问题 $this.text该死 我也有同样的错误 以下是错误: [Error]TypeError:undefined不是计算“a.createDocumentFragment”的对象 db jquery-1.11.1.min.js,第3行 buildFragment jquery-1.11.1.min.js,第3行 domManip jquery-1.11.1.min.js,第3行 追加jque
我不知道是什么问题,需要帮助,谢谢 错误可能是因为它是一个普通对象而不是元素 每个函数都有自己的此值,在调用时确定。并且,在成功回调中,这通常指的是请求的设置
var send = {ff_ID:"",ff_k:""};
send.ff_ID = $(this).attr("id");
send.ff_k = $(this).find("span").text();
$.ajax({
type: "POST",
url: "/funfact_ajax",
cache:true,
dataType:"json",
data:send,
success: function(data){
if(data.success == true){
$(this).text(eval(send.ff_k)+1);
}else{
alert(data.msg);
}
}
});
包括一个上下文选项,用于指定要使用的不同值,以便它也可以引用其中的元素:
$.ajax({
// ...
success: function () {
console.log(this.type, this.url); // "POST" "/funfact_ajax"
}
});
发送的代码应该是…?$this.textdamn;有同样的错误它工作!thx很多
$.ajax({
// ...
context: this,
success: function () {
$(this).text(eval(send.ff_k)+1);
}
});