$.ajax({
async: false,
type: \"POST\",
url: url+\"module/listing/\"+projectId,
data: \"ajax=true\",
success: function(response) {
$.each(resp
I was getting this error while sending an array of column names to jQuery DataTables. The array needs to be an array of objects, not just an array of names. link to columns
BAD columns: ["Column1", "Column2"]
GOOD columns:[{title: "Column1"}, {title: "Column2"}]
Use dataType: "json"
to have jQuery parse the response as JSON. It will solve your problem.
success: function(response) {
response=JSON.parse(response);
$.each(response, function(key, val) {
alert(val.id);
});
}
I had the same problem. The error is being triggered from the jQuery function 'isArraylike( obj )' from the following line:
return type === "array" || type !== "function" &&
( length === 0 ||
typeof length === "number" && length > 0 && ( length - 1 ) in obj );
The Javascript 'in' operator needs an object as operand, so chances are if you do jQuery.type(response) it'll show something other than an object (eg. string or null)
So Amit's answer should work - if not, check the type of the response data and work from there.
Try this one, worked for me
$.each(eval(response), function(key, val)
For some reason (which I don't know), response is considered a string and not an object so you have to 'convert it' using eval()
.
I got this error after I encoded twice a JSON array. Maybe it will help anybody.