Ticket #143 (assigned enhancement)

Opened 2 years ago

Last modified 1 year ago

Add JSONP to Async

Reported by: beau@hartshornesoftware.com Assigned to: beau@hartshornesoftware.com (accepted)
Priority: normal Milestone: MochiKit 1.5
Component: component1 Version:
Severity: normal Keywords:
Cc:

Description (Last modified by beau@hartshornesoftware.com)

I've tried this technique on a production site, and it works pretty well. It's fast, and nobody's written in to complain about leaks or some other problem. It's kind of hackish, but I think it belongs in Async.

JSONP: http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/

JSONscriptRequest: http://www.mapbuilder.net/js/json/0.1/

Attachments

Async.js.addJSONP.diff (3.4 kB) - added by hotchpotch@gmail.com on 09/06/06 19:28:54.
Async.js.addJSONP.v2.diff (3.7 kB) - added by hotchpotch@gmail.com on 09/18/06 23:51:45.
fix WinIE bug

Change History

07/10/06 18:20:17 changed by beau@hartshornesoftware.com

  • description changed.

07/19/06 14:48:31 changed by beau@hartshornesoftware.com

  • owner changed from somebody to beau@hartshornesoftware.com.
  • status changed from new to assigned.

09/06/06 19:27:59 changed by hotchpotch@gmail.com

Hi. I wrote code for JSONP to Async.

DEMO

http://rails2u.com/misc/MochiKitAsyncJSONP/

DEMO is able to get JSON from del.icio.us by JSONP.

DEMO's Implementation example code is like this.

var d = sendJSONPRequest('http://del.icio.us/feeds/json/' + 
$('uid').value, 'callback'); 
d.addCallback(function(json) { 
    replaceChildNodes($('result'), UL(null, map(function(data) { 
        return LI(null, A({href: data.u}, data.d)); 
    }, json))); 
}); 

sendJSONPrequest

sendJSONPrequest is MochiKit.Async's function. {{ sendJSONPRequest: function (url, callbackQuery, timeout/* = 30 */, /* optional */scriptElementAttr) }}

sendJSONPRequest's arguments

- First argument is JSON url.

example: http://del.icio.us/feeds/json/gorou

- Second Arguments is query callback params name. If del.icio.us's API callback name is 'callback'.

- Third argument is request timeout second. If over timeout second. call errback. But don't work opera... Opera's element.appendChild(script) don't ASYNC.

- Forth argument is script element attributes. example:

sendJSONPRequest(url, callback_query, timeout, { 
  charset: 'utf-8' 
}); 

09/06/06 19:28:54 changed by hotchpotch@gmail.com

  • attachment Async.js.addJSONP.diff added.

09/18/06 23:51:45 changed by hotchpotch@gmail.com

  • attachment Async.js.addJSONP.v2.diff added.

fix WinIE bug

10/11/06 16:18:23 changed by beau@hartshornesoftware.com

Thanks for the patch, but JSONP should behave like to loadJSONDoc. sendJSONPRequest should return a deferred that you can use to add callbacks and errbacks. This is a good start, but it still needs work.

01/20/07 18:54:41 changed by beau@hartshornesoftware.com

  • milestone set to MochiKit 1.5.