admin管理员组文章数量:1336415
The error
"Uncaught TypeError: Cannot use 'in' operator to search for 'length' in"
is showing in Google chrome console
$(document).ready(function() {
$("#trackerid").change(function() {
var var_locoid = $("#trackerid option:selected").val();
// alert(var_locoid);
$("#deliverylocation").autoplete({
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=".1.1/jquery.min.js"></script>
The error
"Uncaught TypeError: Cannot use 'in' operator to search for 'length' in"
is showing in Google chrome console
$(document).ready(function() {
$("#trackerid").change(function() {
var var_locoid = $("#trackerid option:selected").val();
// alert(var_locoid);
$("#deliverylocation").autoplete({
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./ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Share
edited Jan 23, 2018 at 6:05
Milan Chheda
8,2493 gold badges22 silver badges35 bronze badges
asked Jan 23, 2018 at 6:01
AjithChaddaAjithChadda
613 silver badges18 bronze badges
2
- Try alert(data); at the top of your success function to verify what data you get back. – Anthony McGrath Commented Jan 23, 2018 at 6:09
-
The
in
operator only works on objects. You are using it on astring
. Make sure your value is anobject
before you using$.map
. I believe, in your case, you will have to parsedata
before using in$.map
...JSON.parse()
– Milan Chheda Commented Jan 23, 2018 at 6:09
2 Answers
Reset to default 4Try this
jQuery.parseJSON(data);
The in operator only works on objects. You are using it on a string. Make sure your value is an object before you using $.map. In this specific case, you have to parse the JSON:
$.map(JSON.parse(data), ...);
本文标签:
版权声明:本文标题:javascript - Autocomplete :Uncaught TypeError: Cannot use 'in' operator to search for 'length' i 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742404355a2468515.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论