Bug Tracker

Ticket #8716 (closed bug: invalid)

Opened 4 years ago

Last modified 3 years ago

getJSON - return object - Unexpected token :

Reported by: cameronjacobs@… Owned by:
Priority: undecided Milestone: 1.next
Component: ajax Version: 1.5.1
Keywords: Cc:
Blocking: Blocked by:

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.

Change History

comment:1 follow-up: ↓ 2 Changed 4 years ago by timmywil

Please provide a reduced test case on  jsfiddle so that we could review your issue further.

Last edited 4 years ago by timmywil (previous) (diff)

comment:2 in reply to: ↑ 1 ; follow-up: ↓ 3 Changed 4 years ago by cameronjacobs@…

Replying to 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.

comment:3 in reply to: ↑ 2 ; follow-up: ↓ 4 Changed 4 years ago by timmywil

Replying to 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.

Last edited 4 years ago by timmywil (previous) (diff)

comment:4 in reply to: ↑ 3 Changed 4 years ago by cameronjacobs@…

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.

comment:5 Changed 4 years ago by timmywil

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.

comment:6 Changed 4 years ago by cameronjacobs@…

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}

comment:7 Changed 4 years ago by timmywil

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.

comment:8 follow-up: ↓ 9 Changed 4 years ago by jaubourg

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.

comment:9 in reply to: ↑ 8 ; follow-up: ↓ 12 Changed 4 years ago by 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.

comment:10 follow-up: ↓ 11 Changed 4 years ago by timmywil

  • Status changed from new to closed
  • Resolution set to invalid
  • Component changed from unfiled to ajax

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.

comment:11 in reply to: ↑ 10 Changed 4 years ago by cameronjacobs@…

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.

comment:12 in reply to: ↑ 9 ; follow-up: ↓ 13 Changed 4 years ago by jaubourg

Replying to 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.

comment:13 in reply to: ↑ 12 Changed 4 years ago by cameronjacobs@…

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.

comment:14 Changed 4 years ago by cameronjacobs@…

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?

Note: See TracTickets for help on using tickets.