title: Can't figure out why php script failing on $.ajax call
body: <p>Here's my jQuery script:</p>
  
  <pre><code>$.ajax({
  type: 'POST',
  url: 'zipCodes.php',
  data: searchZipCode,
  cache: false,
  success: function(response) {
      alert ('response from db search: ' + response);
  },
  error: function(response) {
      console.log(response);
      alert('Query failed, php script returned this response: ' + response);
  }
  });
  </code></pre>
  
  <p>The above script is in the head tag of the html file the form is in. The php script is in the same folder as the html file.</p>
  
  <p>Here's the form:</p>
  
  <pre><code>&lt;form id="frmZipCodeSearch" action=""&gt;
      &lt;label for="txtZipCodeSearch"&gt;Enter a zip code&lt;/label&gt;
      &lt;input type="text" id="txtZipCodeSearch" length="10" maxlength="5" /&gt;
      &lt;input type="submit" id="btnSubmitZipCodeSearch" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I also have verified that "searchZipCode" has a value.</p>
  
  <p>Every time I run the search I get the alert from the error part of the ajax call, which says</p>
  
  <blockquote>
    <p>Query failed, php script returned this response: [object Object]</p>
  </blockquote>
  
  <p>and this  shows in the console:</p>
  
  <blockquote>
    <p>Object {readyState: 0, setRequestHeader: function, getAllResponseHeaders: function, getResponseHeader: function, overrideMimeType: function…}</p>
  </blockquote>
  
  <p>I've tried stripping the php script down to just an echo. I'm not getting any php error logs generated in the folder with the script on the server. Nothing I change seems to give me a different result. With one exception:</p>
  
  <p>The only time I got a different result was when I stripped out the ajax and moved the php script to the file with the form and did a "regular" html form POST method. That worked. But I don't <strong>think</strong> the path is wrong when the php is a different file because I'm not getting a "file not found" in the console.</p>
  
  <p>What the heck am I missing here?</p>
  
  <p><strong>[Additional Info]</strong>
  In response to hek2mgl's answer, I added xhr to the error response and did get some more info in the console:</p>
  
  <pre><code>Uncaught ReferenceError: xhr is not defined     zipCodeSearch.html:57
      $.ajax.error                                zipCodeSearch.html:57
      l                                           jquery-1.8.3.min.js:2
      c.fireWith                                  jquery-1.8.3.min.js:2
      T                                           jquery-1.8.3.min.js:2
      r                                           jquery-1.8.3.min.js:2
  </code></pre>
  
  <p>All other jQuery I'm using is working fine, but this is the first time I've used v1.8.3 myself.</p>
  
  <p><strong>[Answer - credit hek2mgl]</strong>
  As hek2mgl explained in our crazy-long discussion, I was submitting the form twice, because the ajax call was within the click event of the form's button.</p>
  
  <p>The fix for this was to move the ajax call out of the click event into its own function, and after my client-side validation, call the ajax function and add "return false;" after the function call.</p>