title: jQuery aspx error function always called, even with apparently valid return data
body: <p>I am making an <a href="/questions/tagged/ajax" class="post-tag" title="show questions tagged 'ajax'" rel="tag">ajax</a> call using jQuery (jquery-1.5.2.min.js). The server receives the call. <a href="/questions/tagged/fiddler" class="post-tag" title="show questions tagged 'fiddler'" rel="tag">fiddler</a> shows the response text coming back apparently correct. But back in javascript my error: function is called instead of my success: function, and the data of the parameters to the error function don't give much clue as to the problem.</p>
  
  <p>Here's the function where I make the initial call:</p>
  
  <pre><code>function SelectCBGAtClickedPoint()
  {
      $.ajax( {
          type: "GET",
          dataType: "text",
          url: "http://localhost/ajax/SelectCBGAtPoint/1/2",
          success:
              function( msg )
              {
                  alert( "success: " + msg );
              },
          error:
              function( jqXHR, textStatus, errorThrown )
              {
                  alert( "error: " + jqXHR + textStatus + errorThrown );
              }
      } );
  }
  </code></pre>
  
  <p>Here's the function where I handle the call in my <a href="/questions/tagged/cherrypy" class="post-tag" title="show questions tagged 'cherrypy'" rel="tag">cherrypy</a> server code:</p>
  
  <pre><code>def ajax( ajax, *args ):
      with lock:
          print "ajax request received: " + str( args )
  
          cherrypy.response.headers[ "Content-Type" ] = "application/text"
  
          return "{ x: 0 }"
  </code></pre>
  
  <p>Cherrypy is an odd beast, and I was thinking the problem must lie there. But as I say, I see both the query go out and the response come back in Fiddler. Here is what Fiddler shows as the raw view of the response:</p>
  
  <pre><code>HTTP/1.1 200 OK
  Date: Mon, 11 Apr 2011 17:49:25 GMT
  Content-Length: 8
  Content-Type: application/text
  Server: CherryPy/3.2.0
  
  { x: 0 }
  </code></pre>
  
  <p>Looks good, but then back in javascript, I get into the error: function, with the following values for the parameters (as shown in <a href="/questions/tagged/firebug" class="post-tag" title="show questions tagged 'firebug'" rel="tag">firebug</a>):</p>
  
  <pre><code>errorThrown = ""
  jqXHR = Object { readyState=0, status=0, statusText="error"}
  statusText = "error"
  </code></pre>
  
  <p>I don't know where that word "error" is coming from. That string does not appear anywhere in my cherrypy server code.</p>
  
  <p>Note that even though I'm returning a JSON string I've set the send and receive types to "text" for now, just to simplify in order to isolate the problem.</p>
  
  <p>Any ideas why I'm getting this "error" reply, even when errorThrown is empty? Could it be that I haven't properly "initialized" either jQuery or jQuery.ajax?</p>