getJSON - return object - Unexpected token :

Description

When doing a getJSON request after upgrading to jquery-1.5.1 that previously worked on jquery-1.4.4. I am getting the response "Uncaught SyntaxError: Unexpected token: in jquery-1.5.1.min.js at line 16". Sorry I didn't have a chance to find the line number on the non-minified version.

The JSON response was {"LOGGEDIN":false}

This error occurred whether or not I had anything in my success handler.

Unfortunately, I am unable to reproduce your issue. It could be many things, including issues separate from jQuery such as your server config, JSON validity, and others. However, you can mock ajax requests on http://jsfiddle.net, so if you can reproduce the issue, I'd be happy to take a look.

Understood, the question I have is getJSON works perfectly on jquery 1.4.4 and now doesn't work with 1.5.1. I hate to get stuck at an old revision and would like to find the way to solve it, and the only thing that has changed on this server is the version of jquery. This leads me to believe that it's definitely an issue with the version or how the new version validates the JSON.

Can you see anything with the following response that would cause an issue?
{"LOGGEDIN":false}

The ajax component underwent a major rewrite in 1.5. Expectantly, there have been bugs that have popped up due
to this. However, there have also been corrections in the usage of ajax so there may be some things that used to work in 1.4.4 and no longer work that are intentional. So it is difficult to know which it is, or if it is in fact an issue with jQuery, and what you can do to fix it without narrowing down your issue. My suggestion would be to do some more research into your problem. I'd start by switching to an unminified version of 1.5.1 and ask for help in the #jquery support irc channel or the Using jQuery forums to get closer to a resolution.

You probably use an older version of the validation plugin or another plugin that messes with ajax. No matter the culprit, your json request is promoted as a jsonp request and, then, your json is executed as javascript... hence the Unexpected Token error.

I just re-ran a test using just jquery 1.5.1 and jqueryui 1.8.11 and encountered the same error. However, I also found out that running the $.ajax request with dataType of jsonp under jquery 1.4.4 produced the exact same error. So, is there a way to force it to interpret the request as json and not jsonp?

My requests are coming from the same domain and do not have the domain qualified on the url ("/global/login.cfc?wsdl"), so my understanding is that it should be valid as json and it should not need to be running as jsonp.

Yes, if you use $.ajax instead, you can set the jsonp option to false. jQuery does automatic conversion to jsonp in certain use cases, specifically when a callback is provided. For more, see http://api.jquery.com/jQuery.ajax.

Closing this ticket for now. We'd be glad to open again if this is an issue with jQuery.

Thank you very much. setting jsonp = false on a $.ajax request, solved my problem. Also, it works properly if I set jsonp to false in ajaxSetup.

However, if I set jsonp to false in ajaxSetup, and jsonp to false in an $.ajax request, it throws the same error. This sounds like a very minor problem to me, but I expect it's probably a minor bug in the $.ajax implementation.

I just re-ran a test using just jquery 1.5.1 and jqueryui 1.8.11 and encountered the same error. However, I also found out that running the $.ajax request with dataType of jsonp under jquery 1.4.4 produced the exact same error. So, is there a way to force it to interpret the request as json and not jsonp?

My requests are coming from the same domain and do not have the domain qualified on the url ("/global/login.cfc?wsdl"), so my understanding is that it should be valid as json and it should not need to be running as jsonp.

Sorry, I really don't mean to be a pest, but I'm not sure how this applies (except to my comment about setting jsonp to false in ajaxSettings. It seems to work perfectly in the jQuery.ajax call if I apply it, but since I'm currently using jQuery.getJSON everywhere and while I can change it to a jQuery.ajax call and will if that's the more appropriate solution, I would prefer just to modify the ajaxSettings to have the getJSON requests work properly.

However, I suppose my real question is, if setting jsonp to false is hiding a real issue, what is the real issue, because I would like to solve the issue, but it seems like my response is a valid json response, but an invalid jsonp response. Or at least it is parsed as invalid, is this correct?

As I stated above, my current request is replying:
{"LOGGEDIN":false}

It appears to be appropriately structured, I just am not sure why it's having a problem parsing the colon, because it should be reading this as an object and returning the object.

Again, sorry to be a pest, but I do really appreciate the responses, I just do not want to get stuck on a non-current version of jQuery and am willing to make any changes necessary to move forward, I just need to know what they are.

Well, I guess the most appropriate question, is if I wrap my current json response with padding (i.e. something( ... ); ) would this solve the problem. But more directly, why is the request getting promoted to jsonp, since it really should be a json request without padding?