I need to count the length of an Ajax response done in jQuery. The response is in JSON format and only contains a single string. I get the value but have no idea how to coun
If you know the response is not an object then
success: function(response) {
if(response){
alert( (response + '').length );
}
}
will work well.
but if response will be in the form of Object like
[{name:'some-name',details:[....something]}]
I would suggest use below code
success: function(response) {
length=0;
if(response){
length=JSON.stringify(response).length;
}
console.log(length)
}
I think this code will work like a charm for you.