這裏搜索「某事」是我的代碼:不能使用「在」運營商在不確定的
.
.
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
拍攝,我認爲這是一個數據屬性。我的錯。 –