Side navigation
#8716 closed bug (invalid)
Opened March 30, 2011 08:31PM UTC
Closed March 31, 2011 11:46PM UTC
Last modified March 14, 2012 03:56PM UTC
getJSON - return object - Unexpected token :
Reported by: | cameronjacobs@gmail.com | Owned by: | |
---|---|---|---|
Priority: | undecided | Milestone: | 1.next |
Component: | ajax | Version: | 1.5.1 |
Keywords: | Cc: | ||
Blocked by: | Blocking: |
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.
Attachments (0)
Change History (14)
Changed March 30, 2011 08:41PM UTC by comment:1
_comment0: | Please provide a reduced test case on jsfiddle so that we could review your issue further. → 1301517673594526 |
---|---|
_comment1: | Please provide a reduced test case on jsfiddle.net so that we could review your issue further. → 1301517686735811 |
_comment2: | Please provide a reduced test case on [jsfiddle.net] so that we could review your issue further. → 1301517698283913 |
Changed March 30, 2011 08:48PM UTC by comment:2
Replying to [comment:1 timmywil]:
Please provide a reduced test case on jsfiddle so that we could review your issue further.
a test you can run is:
$(document).ready(function(){
$.getJSON("http://yountville.org/global/login.cfc?wsdl", {
method: "getUser"
}, function(result){
alert('a');
});
});
and run http://yountville.org/global/login.cfc?wsdl&method=getUser to test the json response.
Changed March 30, 2011 09:03PM UTC by comment:3
_comment0: | Replying to [comment:2 cameronjacobs@…]: \ You cannot use getJSON for cross-domain json requests unless you provide a callback in the url. If you do not want to provide a callback, use [http://api.jquery.com/jQuery.ajax jQuery.ajax] → 1301519015647586 |
---|
Replying to [comment:2 cameronjacobs@…]:
You cannot use getJSON for cross-domain json requests unless you provide a callback in the url. If you do not want to provide a callback, use jQuery.ajax and set the dataType to jsonp.
Changed March 30, 2011 09:39PM UTC by comment:4
It's actually not cross-domain for me, but just to check, I did run this using a $.ajax call with dateType "json" and "jsonp" and received the same result.
I tried to copy in the code that I ran, but it keeps marking it as spam.... but I used the same url and datatype jsonp as you stated and recieved that exact same error.
Changed March 30, 2011 09:49PM UTC by comment:5
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.
Changed March 30, 2011 09:56PM UTC by comment:6
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}
Changed March 30, 2011 10:20PM UTC by comment:7
Yea that JSON looks valid.
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.
Changed March 30, 2011 11:12PM UTC by comment:8
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.
Check your plugins and control they are 1.5 compatible.
Changed March 31, 2011 11:38PM UTC by comment:9
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.
Thanks, I appreciate the responses.
Changed March 31, 2011 11:46PM UTC by comment:10
component: | unfiled → ajax |
---|---|
resolution: | → invalid |
status: | new → closed |
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.
Changed March 31, 2011 11:56PM UTC by comment:11
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.
Changed April 01, 2011 01:46AM UTC by comment:12
Replying to [comment:9 cameronjacobs@…]:
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. Thanks, I appreciate the responses.
Then you're probably doing something as described in http://bugs.jquery.com/ticket/8084#comment:16
Also, Timmy's suggestion of setting the jsonp option to false just hides the real issue.
Changed April 01, 2011 06:16PM UTC by comment:13
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.
Changed April 01, 2011 06:38PM UTC by comment:14
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?
Please provide a reduced test case on jsfiddle so that we could review your issue further.