我有一个对 doop.php
的 Ajax 调用。
function doop(){
var old = $(this).siblings('.old').html();
var new = $(this).siblings('.new').val();
$.ajax({
url: 'doop.php',
type: 'POST',
data: 'before=' + old + '&after=' + new,
success: function(resp) {
if(resp == 1) {
$(this).siblings('.old').html(new);
}
}
});
return false;
}
我的问题是$(this).siblings('.old').html(new);
这一行没有按照预期执行。
谢谢,所有有用的评论/答案都将被投票支持。
更新: 似乎问题的一半是作用域(感谢帮助我澄清的答案),但另一半是我试图以同步方式使用ajax。 我已经创建了一个新的帖子。
new
是一个保留字:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Lexical_grammar#reserved_keywords_as_of_ecmascript_2015 - Crescent Fresh