Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.ajaxSetup predefines all parameters #210

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 src/reqwest.js
Expand Up @@ -253,8 +253,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