title: Struggling to build a JS/PHP validation function for my app
body: <p>I have a web service that returns a JSON object when the web service is queried and a match is found, an example of a successful return is below:</p>
  
  <p><code>{"terms":[{"term":{"termName":"Focus Puller","definition":"A focus puller or 1st assistant camera..."}}]}</code></p>
  
  <p>If the query does not produce a match it returns:</p>
  
  <p><code>Errant query: SELECT termName, definition FROM terms WHERE termID = xxx</code></p>
  
  <p>Now, when I access this through my Win 8 Metro app I parson the JSON notation object using the following code to get a JS object:</p>
  
  <p><code>var searchTerm      = JSON.parse(Result.responseText)</code></p>
  
  <p>I then have code that processes <code>searchTerm</code> and binds the returned values to the app page control. If I enter in a successful query that finds match in the DB everything works great.</p>
  
  <p>What I can't work out is a way of validating a bad query. I want to test the value that is returned by <code>var searchTerm      = JSON.parse(Result.responseText)</code> and continue doing what I'm doing now if it is a successful result, but then handle the result differently on failure. What check should I make to test this? I am happy to implement additional validation either in my app or in the web service, any advice is appreciated. </p>
  
  <p>Thanks! </p>