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), ...);