jQuery aspx error function always called, even with apparently valid return data

Posted by M Katz on Stack Overflow See other posts from Stack Overflow or by M Katz
Published on 2011-04-11T18:14:55Z Indexed on 2012/06/01 16:40 UTC
Read the original article Hit count: 337

Filed under:
|
|

I am making an call using jQuery (jquery-1.5.2.min.js). The server receives the call. 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.

Here's the function where I make the initial call:

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 );
            }
    } );
}

Here's the function where I handle the call in my server code:

def ajax( ajax, *args ):
    with lock:
        print "ajax request received: " + str( args )

        cherrypy.response.headers[ "Content-Type" ] = "application/text"

        return "{ x: 0 }"

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:

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 }

Looks good, but then back in javascript, I get into the error: function, with the following values for the parameters (as shown in ):

errorThrown = ""
jqXHR = Object { readyState=0, status=0, statusText="error"}
statusText = "error"

I don't know where that word "error" is coming from. That string does not appear anywhere in my cherrypy server code.

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.

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?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about AJAX