Jquery Ajax Json Response Has Length Undefined And Incorrect Data
I'm trying to grab a dictionary object which is converted to json object in server side, (along with correct content-type header), but for some reason, even though I can access par
Solution 1:
Objects don't have a length property unless you give them one. Arrays do, but arrays are created with []
not {}
.
If you want to know how many properties an object has, you have to loop over them and count them:
var count = 0;
for (var foo in bar) {
if (bar.hasOwnProperty(foo) {
count++;
}
}
Solution 2:
Best way to debug this is to inspect the response under Firebug console. See if you are even getting back a valid response.
Solution 3:
You can convert your object to JSON
using :
var jsonVariable= JSON.stringify(objectVariable);
var jsonVariableLength = jsonVariable.length ;
And print the length :
alert('Length : ' + jsonVariableLength );
Post a Comment for "Jquery Ajax Json Response Has Length Undefined And Incorrect Data"