title: jquery ajax ignores 500 status error
body: <p>I'm making some GET requests to an App Engine app, testing in Chrome. Whilst I can see in javascript console that some calls result in a 500 server error, I can't seem to find anyway of capturing this error in my jQuery code despite reading a number of similar SO threads. I understand that it indicates a server side error, but I'd still like to be able to capture such an error from my javascript.</p>
  
  <p>I need to capture the error so that I can count the number of responses (successful or otherwise) and trigger another function when all call responses have been received.</p>
  
  <p>Chrome console output:</p>
  
  <pre><code>GET http://myapp.com/api?callback=jQuery12345&amp;params=restOfParams 500 (Internal Server Error)
  </code></pre>
  
  <p>My call:</p>
  
  <pre><code>  function makeCall() {
      var count = 0;
      var alldata = $('#inputset').val();
      var rows = alldata.split('\n');
      var countmatch = rows.length;
      for (i=0;i&lt;rows.length;i++) {
        data["param"] = rows[i]["val"];
        $.ajax({
                url: apiUrl,
                type: 'GET',
                data: data,
                dataType: 'jsonp',
                error: function(){
                    alert('Error loading document');
                    count +=1;
                },
                success: function(responseJson) {
                              count +=1;
                              var res = responseJson.results;
                              if (count == countmatch) {
                                allDoneCallback(res);
                              }
                          },
               });
      }
  }
  </code></pre>
  
  <p>I've tried some of the following:<br>
  Adding:</p>
  
  <pre><code>statusCode: {500: function() {alert('err');}}
  </code></pre>
  
  <p>to the call.</p>
  
  <p>Using:</p>
  
  <pre><code>  $().ready(function(){
       $.ajaxSetup({
         error:function(x,e) {
               if(x.status==500) {
                 alert('Internel Server Error.');
               }
             }
        });
     });
  </code></pre>
  
  <p>Would anyone have a suggestion regarding how I could catch the 500 response?</p>
  
  <p>Thanks
  Oli</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Based on responses, my jquery code appears to be correct, but for some reason it would only catch certain 500 responses received from my app. This is possibly a problem with how App Engine returns the error(I don't know a lot about this), or how jquery handles errors with jsonp - this point is briefly discussed in the last paragraph of <a href="http://www.ibm.com/developerworks/library/wa-aj-jsonp1/">this</a> article.</p>
  
  <p>I got this to work by using <a href="http://code.google.com/p/jquery-jsonp/">jquery-isonp</a> which caught all of the 500 status's thrown by the app. </p>