Skip to content

Utility class to allow users to easily make use of JSONP callback data in Dart

Notifications You must be signed in to change notification settings

chrisbu/DartJSONP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 

Repository files navigation

DartJSONP

Last tested working (Dartium, JS) with build 8942

(Created at the London Dart hackathon)

Inspired by Seth's blog post which explained how to use JSONP and postmessage with Dart: http://blog.sethladd.com/2012/03/jsonp-with-dart.

Allow easy JSONP data access without the fuss by injecting and removing a javascript callback function or Future and a dart postmessage handler function

For example (with callback):

var callbackFuncName = "twitterFunction";
JsonpCallback twitterCallback = new JsonpCallback(callbackFuncName);
twitterCallback.onDataReceived = (Map data) {
  // do something with the returned data
};

var twitterUrl = "http://search.twitter.com/search.json?q=dartlang&callback=$callbackFuncName";
twitterCallback.doCallback(twitterUrl);

For example (with Future):

var callbackFuncName = "twitterFunction";
JsonpCallback twitterCallback = new JsonpCallback(callbackFuncName);

var twitterUrl = "http://search.twitter.com/search.json?q=dartlang&callback=$callbackFuncName";
twitterCallback.doCallback(twitterUrl).then((Map data) {
  // do something with the returned data
});

You can see this running here: http://example.dartwatch.com/jsonp/DartJsonPtest.html

Internally, it adds the javascript, performs the request and when the callback is received by javascript and forwarded back to dart, it removes the scripts (as best it can), to clean up after itself.

About

Utility class to allow users to easily make use of JSONP callback data in Dart

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •