Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

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

branch: master
README.md

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.

Something went wrong with that request. Please try again.