I have a script where I get some data through JSON, this is like :
$.getJSON('phpfile', function(data) { ...
it works perfectly when I receive some data but when its empty, I get the next error :
Uncaught TypeError: Cannot read property ‘length’ of null
Where I get this error is a line like this one :
if(data==null){
//actions if the JSON is doesnt give me data
}else{
//actions if I get data
}
What I want is to control when JSON sends data or not, how can I do it ?
EDIT: I get the error with $.each(data, function(key, val) { when data is a null object, when json doesn’t get any data.
Thanks in advance
1 Answer