add example for m.request config

This commit is contained in:
Leo Horie 2014-04-08 15:33:54 -04:00
parent b2daa1b55a
commit 3f8c630702
3 changed files with 22 additions and 0 deletions

Binary file not shown.

View file

@ -213,6 +213,14 @@ var users = User.list();
url: "myfile.txt",
deserialize: function(value) {return value;}
});</code></pre>
<h3 id="configuring-the-underlying-xmlhttprequest">Configuring the underlying XMLHttpRequest</h3>
<p>The <code>config</code> option can be used to arbitrarily configure the native XMLHttpRequest instance and to access properties that would not be accessible otherwise.</p>
<p>The example below show how to configure a request where the server expects requests to have a <code>Content-Type: application/json</code> header</p>
<pre><code class="lang-javascript">var xhrConfig = function(xhr) {
xhr.setRequestHeader(&quot;Content-Type&quot;, &quot;application/json&quot;);
}
m.request({method: &quot;POST&quot;, url: &quot;/foo&quot;, config: xhrConfig});</code></pre>
<hr>
<h3 id="signature">Signature</h3>
<p><a href="how-to-read-signatures.html">How to read signatures</a></p>

View file

@ -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