2.0.0 • Published 7 years ago

tot-ajax v2.0.0

Weekly downloads
1
License
MIT
Repository
-
Last release
7 years ago

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 ajax function returns an ajaxObj wrapper object for new XMLHttpRequest().
  • Wrapper properties: method, url, async, user, password, xhr, response.
  • Wrapper methods: run, get, post, put, delete.
  • run sends the xhr with method; other methods just set method and call run.
  • 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_args won'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_args manually.
2.0.0

7 years ago

1.1.10

7 years ago

1.1.9

7 years ago

1.1.8

7 years ago

1.1.7

7 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago