2.0.0 • Published 9 years ago
tot-ajax v2.0.0
tot-ajax
Minimalistic browser script for ajax.
Usage
ajax(url, [async=true], [user], [password])
.get([data], [callback(err, res, xhr, ajaxObj)])
.then( (res, xhr, ajaxObj) => { ... } )- Call to
ajaxfunction returns anajaxObjwrapper object fornew XMLHttpRequest(). - Wrapper properties:
method,url,async,user,password,xhr,response. - Wrapper methods:
run,get,post,put,delete. runsends thexhrwithmethod; other methods just setmethodand callrun.- Methods accept optional callback and return a promise.
- If data passed to a method is an object (except FormData) then it gets automatically stringified and sent with
'Content-Type: application/json'header. - If response has
'Content-Type: application/json'header then it gets automatically parsed.
Examples
Say we want to update Jayson's email and imagine the server sends the whole updated user object in the response.
ajax('/users?name=Jayson')
.post({email: 'jayson_parser@mail.com'})
.then( user => {
console.log(user.name + "'s email is " + user.email)
})Installation
npm install tot-ajax
Advanced installation
This command will produce a single .js file in the current working directory:
Linux: _npm_postinstall_args=justmain npm i tot-ajax
Windows: set _npm_postinstall_args=justmain & npm i tot-ajax
- The error after installing this way is a trick to make npm safely remove module directory.
- On Windows
_npm_postinstall_argswon't be reset after command execution, so if you want to install the module normally after installing it "advanced" way then you should restart the shell or clear_npm_postinstall_argsmanually.
2.0.0
9 years ago
1.1.10
9 years ago
1.1.9
9 years ago
1.1.8
9 years ago
1.1.7
9 years ago
1.1.6
9 years ago
1.1.5
9 years ago
1.1.4
9 years ago
1.1.3
9 years ago
1.1.2
9 years ago
1.1.1
9 years ago
1.1.0
9 years ago
1.0.7
9 years ago
1.0.6
9 years ago
1.0.5
9 years ago
1.0.4
9 years ago
1.0.3
9 years ago
1.0.2
9 years ago
1.0.1
9 years ago
1.0.0
9 years ago