From 3f8c630702ea7c708b01d7b0574c0e62e3ccf459 Mon Sep 17 00:00:00 2001 From: Leo Horie Date: Tue, 8 Apr 2014 15:33:54 -0400 Subject: [PATCH] add example for m.request config --- archive/v0.1.4/mithril.min.zip | Bin 20825 -> 20825 bytes archive/v0.1.4/mithril.request.html | 8 ++++++++ docs/mithril.request.md | 14 ++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/archive/v0.1.4/mithril.min.zip b/archive/v0.1.4/mithril.min.zip index 3dede029703860560b241a31980c72f2ff8fbc33..74333ec87e18022ade5ec08dc43fd2d405dc2dc5 100644 GIT binary patch delta 45 vcmcb)i1FqkMxFp~W)?065HPCQ$n#c?$*5-YZ@JrsKzj0x04oqB66gv5JLwKV delta 45 vcmcb)i1FqkMxFp~W)?065QwVS$n#c?DXL=gZ@JrsKzj0x04oqB66gv5MTrj4 diff --git a/archive/v0.1.4/mithril.request.html b/archive/v0.1.4/mithril.request.html index 728c8f68..eeeb33ed 100644 --- a/archive/v0.1.4/mithril.request.html +++ b/archive/v0.1.4/mithril.request.html @@ -213,6 +213,14 @@ var users = User.list(); url: "myfile.txt", deserialize: function(value) {return value;} }); +

Configuring the underlying XMLHttpRequest

+

The config option can be used to arbitrarily configure the native XMLHttpRequest instance and to access properties that would not be accessible otherwise.

+

The example below show how to configure a request where the server expects requests to have a Content-Type: application/json header

+
var xhrConfig = function(xhr) {
+    xhr.setRequestHeader("Content-Type", "application/json");
+}
+
+m.request({method: "POST", url: "/foo", config: xhrConfig});

Signature

How to read signatures

diff --git a/docs/mithril.request.md b/docs/mithril.request.md index 7cdfee61..27cac116 100644 --- a/docs/mithril.request.md +++ b/docs/mithril.request.md @@ -226,6 +226,20 @@ var file = m.request({ }); ``` +### Configuring the underlying XMLHttpRequest + +The `config` option can be used to arbitrarily configure the native XMLHttpRequest instance and to access properties that would not be accessible otherwise. + +The example below show how to configure a request where the server expects requests to have a `Content-Type: application/json` header + +```javascript +var xhrConfig = function(xhr) { + xhr.setRequestHeader("Content-Type", "application/json"); +} + +m.request({method: "POST", url: "/foo", config: xhrConfig}); +``` + --- ### Signature