Skip to main content

Bug Tracker

Side navigation

#12226 closed bug (invalid)

Opened August 09, 2012 04:54AM UTC

Closed August 14, 2012 11:42AM UTC

concurrent jsonp ajax requests with the same jsonpCallback value fail with an undefined callback

Reported by: anonymous Owned by:
Priority: low Milestone: None
Component: ajax Version: 1.8.0
Keywords: Cc:
Blocked by: Blocking:
Description

With an error message:

TypeError: 'undefined' is not a function (evaluating 'callback({"count": "3"})')

jsfiddle here: http://jsfiddle.net/Wn4HH/3/

Additional calls beyond the first appear to overwrite the global callback function.

Attachments (0)
Change History (1)

Changed August 14, 2012 11:42AM UTC by sindresorhus comment:1

_comment0: You're specifying a the name of a callback handler without actually creating it. \ \ \ From [http://api.jquery.com/jQuery.ajax/ docs]: \ \ > Specify the callback function name for a JSONP request. This value will be used instead of the random name automatically generated by jQuery. It is preferable to let jQuery generate a unique name as it'll make it easier to manage the requests and provide callbacks and error handling. You may want to specify the callback when you want to enable better browser caching of GET requests. As of jQuery 1.5, you can also use a function for this setting, in which case the value of jsonpCallback is set to the return value of that function. \ \ Example: http://jsfiddle.net/Wn4HH/4/1344944548413724
component: unfiledajax
priority: undecidedlow
resolution: → invalid
status: newclosed
version: 1.7.21.8.0

You're specifying a the name of a callback handler without actually creating it.

From docs - jsonpCallback:

Specify the callback function name for a JSONP request. This value will be used instead of the random name automatically generated by jQuery. It is preferable to let jQuery generate a unique name as it'll make it easier to manage the requests and provide callbacks and error handling. You may want to specify the callback when you want to enable better browser caching of GET requests. As of jQuery 1.5, you can also use a function for this setting, in which case the value of jsonpCallback is set to the return value of that function.

Example: http://jsfiddle.net/Wn4HH/4/