1

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?

3
  • 1
    That "error" keyword is coming out of jQuery, it's what it sets statusText to if it sees an error. But that certainly is weird in your case since you clearly have a 200 response. Maybe try getting the unminified version of jQuery and step through the ajax response handling part?
    – Milimetric
    Apr 11, 2011 at 19:22
  • @Milimetric, thanks for the suggestion. I did step through the code in jquery, and I noticed that the crossDomain boolean was set in some of the message handling structures. So ... D'oh! I had my browser pointed to a file://C:/... URL, and jquery was considering my ajax call to htt p://localhost/... to be "cross domain", which I guess makes sense. It's more like "cross protocol", but it makes sense that jquery barfs on it. I guess my only suggestion would be for jquery to modify the error string in this case to complain about cross domain or cross protocol to give a clue of what happened.
    – M Katz
    Apr 12, 2011 at 0:07
  • agreed on more detailed error messages
    – Milimetric
    Apr 12, 2011 at 0:38

1 Answer 1

0

My problem was the same as M Katz, I had my browser pointed to a file:///c:/temp.html and jquery was considering my request to be cross domain. However, setting the crossDomain property to true had no effect. I had to move the page under my web project, but once I did everything magically started to work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.