The JSON response looks like this when it is empty when viewed in the browser console:
{"data":{},"status":200,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"jsonpCallbackParam":"callback","url":"http://url/form/BN217473","headers":{"Accept":"application/json, text/plain, */*"}},"statusText":"","xhrStatus":"complete"}
In angular script I am checking if the response is empty but the check is not catching the empty response as the logic block is never executed
if (response.data == '') {
console.log("no data found");
}
How can I check that my response is not empty?
Try below code snippet:-
if(!Object.keys(response.data).length){
console.log("no data found");
}
If you are getting data as empty object like data: {}, then you should check if there is any key inside the object or not.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With