Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you are using a remote data source (like a MySQL database, <a href="http://en.wikipedia.org/wiki/PHP" rel="nofollow">PHP</a>, or whatever on the server side) there are a couple of other cleaner ways to handle a situation when there's no data to return to the client (without the need for any hacks or core code UI code changes).</p> <p>I use PHP and MySQL as my remote data source and JSON to pass information between them. In my case I seemed to get jQuery exception errors if the JSON request did not get some sort of response from the server, so I found it easier to just return an empty JSON response from the server side when there's no data and then handle the client response from there:</p> <pre><code>if (preg_match("/^[a-zA-Z0-9_]*$/", $_GET['callback'])) {//sanitize callback name $callback = $_GET['callback']; } else { die(); } die($callback . "([])"); </code></pre> <p>Another way would be to return a flag in the response from the server to indicate that there's no matching data and perform actions client side based on the presence (and or value) of the flag in the response. In this case the servers response would be something like:</p> <pre><code>die($callback . "([{'nodata':true}])"); </code></pre> <p>Then based on this flag actions can be performed client side:</p> <pre><code>$.getJSON('response.php?callback=?', request, function (response) { if (typeof response[0].nodata !== 'undefined' &amp;&amp; response[0].nodata === true) { alert('No data to display!'); } else { //Do whatever needs to be done in the event that there is actually data to display. } }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload