Page 1 of 1

How to check if REST service response is empty?

Posted: Tue Feb 04, 2014 4:53 pm
by Nathan Friend

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?


How to check if REST service response is empty?

Posted: Tue Feb 04, 2014 6:12 pm
by Maryna Brodina

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.


How to check if REST service response is empty?

Posted: Tue Feb 04, 2014 6:41 pm
by Nathan Friend

This is what the response looks like when it has no records.

{

Code: Select all

"html_attributions" : [ 

 ], 

"results" : [ 

 ], 

"status" : "ZERO_RESULTS" 

}


How to check if REST service response is empty?

Posted: Tue Feb 04, 2014 7:12 pm
by Nathan Friend

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....
}


How to check if REST service response is empty?

Posted: Tue Feb 04, 2014 7:44 pm
by Maryna Brodina

Thank you for update!


How to check if REST service response is empty?

Posted: Mon Jul 20, 2020 12:56 pm
by Nathan Friend

photo_reference"" : ""CnRoAAAA8fKvfU3e_XzU5HK2-6h8bgpcZSyOlcpUGzE_o85f6SMmaVEvdi4O8zx2hnfoTkWvA4SKDYFhKmOqyquCthtAg-SdTXbgwnXwh5Y8H1547rLYswUAshGQSNsMRLDF1ZSiJpYco0JaKmAEeszvLilV0xIQLsgocTlvzqdKQInsJLMGaBoUVF9bMeyUFSSA4jAyzZ5XIDb56do""