Skip to content

Commit

Permalink
.ajaxSetup predefines all parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Georg Tavonius authored and Georg Tavonius committed Sep 12, 2015
1 parent e1e2a6f commit 587e485
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 3 deletions.
12 changes: 12 additions & 0 deletions README.md
Expand Up @@ -166,6 +166,18 @@ var r = reqwest({
* `complete` A function called whether the request is a success or failure. Always called when complete.
* `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.

## Predefined options

Use `.ajaxSetup` to set up predefined values for all options, like headers.

``` js
reqwest.ajaxSetup({
headers: {
'X-CSRF-Token': document.querySelector('[name="csrf-token"]').content
}
});
```

## Security

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
Expand Down
13 changes: 12 additions & 1 deletion reqwest.js
Expand Up @@ -261,8 +261,19 @@
}

function init(o, fn) {
o = typeof o === 'string' ? { url: o } : o
for (var k in globalSetupOptions) {
if (typeof globalSetupOptions[k] === 'object') {
o[k] = o[k] ? o[k] : {}
for (var k2 in globalSetupOptions[k]) {
o[k][k2] = typeof o[k][k2] === 'undefined' ? globalSetupOptions[k][k2] : o[k][k2]
}
} else {
o[k] = typeof o[k] === 'undefined' ? globalSetupOptions[k] : o[k]
}
}

this.url = typeof o == 'string' ? o : o['url']
this.url = o['url']
this.timeout = null

// whether request has been fulfilled for purpose
Expand Down

0 comments on commit 587e485

Please sign in to comment.