这里搜索“某事”是我的代码:不能使用“在”运营商在不确定的
.
.
keydown: function(ev) {
clearTimeout($(this).data('timer'));
if ('abort' in $(this).data('xhr')) $(this).data('xhr').abort(); // error here
var xhr, timer = setTimeout(function() {
xhr = $.ajax({
url : '/files/tags_autocomplete.php',
dataType : 'JSON',
success : function (tags) {
$("ul").html(tags.output);
}
});
}, 500);
$(this).data({timer : timer, xhr : xhr});
}
.
.
正如我评论说,第三行引发此错误:
Uncaught TypeError: Cannot use 'in' operator to search for 'abort' in undefined
哪有我修复它?
[IN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/in)是用来寻找一个属性在一个对象或数组中,我不认为'$(this).data(“xhr”)'是 –
@SterlingArcher'$(this).data(“xhr”)'是'xhr'的值变量,它是'$ .ajax'返回的'jqXHR'对象。 – Barmar
拍摄,我认为这是一个数据属性。我的错。 –