Skip to content

Commit 587e485

Browse files
Georg TavoniusGeorg Tavonius
authored andcommitted
.ajaxSetup predefines all parameters
1 parent e1e2a6f commit 587e485

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,18 @@ var r = reqwest({
166166
* `complete` A function called whether the request is a success or failure. Always called when complete.
167167
* `jsonpCallback` Specify the callback function name for a `JSONP` request. This value will be used instead of the random (but recommended) name automatically generated by reqwest.
168168

169+
## Predefined options
170+
171+
Use `.ajaxSetup` to set up predefined values for all options, like headers.
172+
173+
``` js
174+
reqwest.ajaxSetup({
175+
headers: {
176+
'X-CSRF-Token': document.querySelector('[name="csrf-token"]').content
177+
}
178+
});
179+
```
180+
169181
## Security
170182

171183
If you are *still* requiring support for IE6/IE7, consider including [JSON3](https://bestiejs.github.io/json3/) in your project. Or simply do the following

reqwest.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,19 @@
261261
}
262262

263263
function init(o, fn) {
264+
o = typeof o === 'string' ? { url: o } : o
265+
for (var k in globalSetupOptions) {
266+
if (typeof globalSetupOptions[k] === 'object') {
267+
o[k] = o[k] ? o[k] : {}
268+
for (var k2 in globalSetupOptions[k]) {
269+
o[k][k2] = typeof o[k][k2] === 'undefined' ? globalSetupOptions[k][k2] : o[k][k2]
270+
}
271+
} else {
272+
o[k] = typeof o[k] === 'undefined' ? globalSetupOptions[k] : o[k]
273+
}
274+
}
264275

265-
this.url = typeof o == 'string' ? o : o['url']
276+
this.url = o['url']
266277
this.timeout = null
267278

268279
// whether request has been fulfilled for purpose

0 commit comments

Comments
 (0)