Bug Tracker

Opened 14 years ago

Closed 13 years ago

#4206 closed enhancement (fixed)

Patch: JSONP: Support callbackName to request content with a constant URL

Reported by: ion Owned by:
Priority: minor Milestone: 1.4
Component: ajax Version: 1.4a1
Keywords: jsonp callback Cc:
Blocked by: Blocking:


Say, your page requests http://ws.audioscrobbler.com/2.0/?method=user.getweeklyartistchart&user=...&format=json&callback=foo using JSONP. The response doesn’t change often and it isn’t urgent to get the most recent possible version.

Currently the callback name will be different for each request. If there were a way to keep the callback name constant for that specific request, both the browser and the server could cache the content.

The attached patch implements the callbackName parameter for $.ajax, so that

$.ajax ({
  url:          'http://ws.audioscrobbler.com/...&callback=?',
  success:      ...,
  dataType:     'json',
  callbackName: 'AudioScrobblerChart'

requests http://ws.audioscrobbler.com/...&callback=jsonpAudioScrobblerChart.

The patch throws an error if the programmer uses the same callbackName twice simultaneously.

Attachments (1)

jquery-callbackname.diff (1.7 KB) - added by ion 14 years ago.

Download all attachments as: .zip

Change History (4)

Changed 14 years ago by ion

Attachment: jquery-callbackname.diff added

comment:1 Changed 14 years ago by john

Resolution: wontfix
Status: newclosed

It doesn't really seem like this is needed. If you're really worried about static naming you could just do:

$.ajax ({
  url:          'http://ws.audioscrobbler.com/...&callback=AudioScrobblerChart',
  dataType:     'script'

function AudioScrobblerChart(json){
   // do stuff with the JSON

...which isn't really a huge stretch.

comment:2 Changed 14 years ago by tudor_s

Resolution: wontfix
Status: closedreopened

I also came about making the same patch as posted here. It would really benefit caching by having this option. Especially when you want your other jQuery plugins to use the same settings without the need to change the way they request data.

Therefore this change would really be appreciated, especially when it comes with a small cost to implementing it.

Thank you.

comment:3 Changed 13 years ago by john

Resolution: fixed
Status: reopenedclosed
Note: See TracTickets for help on using tickets.