Quantcast
Channel: SAPUI5 Developer Center
Viewing all articles
Browse latest Browse all 789

Check JSON data length and Error property in Ajax call(SAPUI5).

$
0
0

Hi,

 

Please find the below code that will help you to display a custom message to user if you are not finding any data from XSODATA service.

 

jQuery.ajax({

 

                url : "your URL"

 

                dataType : "json",

              

                success : function(data, textStatus, jqXHR) { // callback  called when data is received

                                                         

                   if (data.d.results.length == 0) { // if data length is 0 then it assumnes that No matching data found and append the message

                                               

                        $('#errorMsg').show();

 

                    } else {

                        // fill the received data into the JSONModel

                    }

                },

 

                error : function(jqXHR, textStatus, errorThrown) {

 

                    $('#error').show();     //This will help you to throw a message to the user if URL is not correct like (404,401 etc)

 

                }

 

            });

 

 

 

<html>

    <body>

         <div id='errorMsg' class="display">

                <p>No Data Found</p>

         </div>

        <div id='error' class="display">

                <p>404 No Found</p>

         </div>

    </body>

</html>


Viewing all articles
Browse latest Browse all 789

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>