错误
“未捕获的TypeError:无法使用'in'运算符来搜索”length“
正在谷歌Chrome控制台中显示
$(document).ready(function() {
$("#trackerid").change(function() {
var var_locoid = $("#trackerid option:selected").val();
// alert(var_locoid);
$("#deliverylocation").autocomplete({
source: function(request, response) {
var auto_data = $("#deliverylocation").val();
// alert(auto_data);
//alert(var_locoid);
$.ajax({
url: "http://localhost/CodeProject/Testctrl/lookup",
type: "POST",
datatype: "json",
//returnType:"json",
data: {
'var_locoid': var_locoid,
'auto_data': auto_data
},
success: function(data) {
var resp = $.map(data, function(obj) {
return obj.tag;
});
response(resp);
}
});
},
minLength: 1
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
试试这个
jQuery.parseJSON(data);
in运算符仅适用于对象。您正在使用字符串。在使用$ .map之前,请确保您的值是一个对象。在这种特定情况下,您必须解析JSON:
$.map(JSON.parse(data), ...);