Bug Tracker

Modify

Ticket #6327 (closed bug: invalid)

Opened 3 years ago

Last modified 3 years ago

.getJSON callback fires before request returns

Reported by: flying_fingersyka Owned by:
Priority: Milestone: 1.4.3
Component: unfiled Version: 1.4.2
Keywords: .getJSON callback Cc:
Blocking: Blocked by:

Description

$.getJSON (and $.ajax with dataType:'json') seem to fail for some reason when getting a json object from Twitter. For example: $.getJSON(' http://search.twitter.com/trends.json', function(json, textStatus) {

alert(textStatus); alert(json);

}); In the upper case, the textStatus is alerted as "SUCCESS", but the json object is alerted as "null". The Twitter json objects are valid. In fact when I download the very same trends.json file and put it in a local directory $.getJSON works fine: $.getJSON(' http://127.0.0.1/sample/trends.json', function(json, textStatus) {

alert(textStatus); alert(json);

}); In this case the textStatus is "SUCCESS" and the json object is alerted as [object Object]...and naturally all further manipulations with the json object work. I also tried getting the same trends.json file from my own web domain and it FAILED again. Basically it fails for any URL apart from the local one. Thus, my logic tells me that, since getting the json file from external server takes a bit more time, the callback function fires before that data is received. That would explain why it works on a local server when respond time is faster...

I would very much appreciate some thoughts on the matter and possibly a workaround..Let me know if you need any more details Thanks a bunch!!!

Change History

comment:1 Changed 3 years ago by dmethvin

$.getJSON is just a wrapper around $.ajax for a simple case. You can't make a cross-domain request with xmlhttprequest, only jsonp. The Twitter API delivers plain text/json file and it appears from their docs that you can't use the standard callback=? notation to turn it into jsonp, where the requested page would call your callback with the json.

This isn't a bug in jQuery so it would be best to continue the discussion on  http://forum.jquery.com if needed.

comment:2 Changed 3 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.