I need to know how to check if a Rest Service response is empty. I found another post on here that said to use if(data.length == 0){} but that does not seem to work for me. Is there something I am missing?
I need to know how to check if a Rest Service response is empty. I found another post on here that said to use if(data.length == 0){} but that does not seem to work for me. Is there something I am missing?
Hello! What is returned in response? Does the method you've posted work if you expect array in response? If you expect an object for example please check are there obligatory (those ones which can't be empty) properties in data object.
This is what the response looks like when it has no records.
{
Code: Select all
"html_attributions" : [
],
"results" : [
],
"status" : "ZERO_RESULTS" }
Okay, I realize what I was doing wrong.
I had to target the results data directly like this.
if(data.status == 'ZERO_RESULTS'){
// do something....
}
Thank you for update!
photo_reference"" : ""CnRoAAAA8fKvfU3e_XzU5HK2-6h8bgpcZSyOlcpUGzE_o85f6SMmaVEvdi4O8zx2hnfoTkWvA4SKDYFhKmOqyquCthtAg-SdTXbgwnXwh5Y8H1547rLYswUAshGQSNsMRLDF1ZSiJpYco0JaKmAEeszvLilV0xIQLsgocTlvzqdKQInsJLMGaBoUVF9bMeyUFSSA4jAyzZ5XIDb56do""