下面是我的ajax调用
$(document).ready(function() {
$("#blog").focusout(function() {
alert('Focus out event call');
alert('hello');
$.ajax({
url: '/homes',
method: 'POST',
data: 'blog=' + $('#blog').val(),
success: function(result) {
$.each(result, function(key, val) {
$("#result").append('<div><label>' + val.description + '</label></div>');
});
},
error: function() {
alert('failure.');
}
});
});
});
我的控制台出现“TypeError: invalid 'in' operand obj '”错误
提前谢谢
最佳答案
在您的 ajax 调用中提及 dataType 属性。它默认考虑文本。这就是为什么无法迭代结果
dataType:'json'
因为你的result应该是数组或者json
关于javascript - 获取类型错误 : invalid 'in' operand obj while fetching data using ajax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18460368/