Nathan Friend
Posts: 0
Joined: Fri Jan 31, 2014 3:56 pm

How to check if REST service response is empty?

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?

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

How to check if REST service response is empty?

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.

Nathan Friend
Posts: 0
Joined: Fri Jan 31, 2014 3:56 pm

How to check if REST service response is empty?

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

{

Code: Select all

"html_attributions" : [ 

 ], 

"results" : [ 

 ], 

"status" : "ZERO_RESULTS" 

}

Nathan Friend
Posts: 0
Joined: Fri Jan 31, 2014 3:56 pm

How to check if REST service response is empty?

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

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

How to check if REST service response is empty?

Thank you for update!

Nathan Friend
Posts: 0
Joined: Fri Jan 31, 2014 3:56 pm

How to check if REST service response is empty?

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

Return to “Issues”