From c7069b9ae44b8f003c5a82b207084fdb7ff57a28 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Tue, 4 Nov 2014 22:09:24 -0500 Subject: [PATCH] improve docs re: jsonp --- docs/mithril.request.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/mithril.request.md b/docs/mithril.request.md index 12f8f73a..be435f21 100644 --- a/docs/mithril.request.md +++ b/docs/mithril.request.md @@ -16,6 +16,7 @@ - [Custom request rejections](#custom-request-rejections) - [Configuring the underlying XMLHttpRequest](#configuring-the-underlying-xmlhttprequest) - [Aborting a request](#aborting-a-request) +- [Using JSON-P](#using-json-p) - [Signature](#signature) --- @@ -362,6 +363,26 @@ transport().abort(); --- +### Using JSON-P + +To make JSON-P requests, add the `dataType` option instead of `method`. You should not add the `callback` querystring parameter; Mithril already does that internally. + +```javascript +m.request({dataType: "jsonp", url: "/api/User"}); +``` + +Some services (e.g. Flickr) don't follow the convention of calling the `callback` parameter `callback`. In order to specify the name of the querystring parameter that indicates the callback function, use the `callbackKey` option: + +```javascript +m.request({ + dataType: "jsonp", + callbackKey: "jsoncallback", + url: "http://api.flickr.com/services/feeds/photos_public.gne?tags=monkey&tagmode=any&format=json" +}); +``` + +--- + ### Signature [How to read signatures](how-to-read-signatures.md)