als-ajax

4.0.0 • Public • Published

Als-ajax

All methods syntax:

Ajax.get(url)
Ajax.post(url,data,headers)
Ajax.put(url,data,headers)
Ajax.delete(url,data,headers)
Ajax.send({url,data,method,headers={}},content=true) // content adding Content-type to headers
Ajax.submit(event,fn)

On post,put,delete methods, "Content-type": "application/x-www-form-urlencoded" added to headers.

Post

Ajax.post('/test/',{test:'hello'})
   .then(data => console.log(data.response))

(async function() {
   let data = await Ajax.post('/test/',{test:'hello'})
   console.log(data.response)
})()

Submit

If form includes input with type=file, 'Content-Type': 'multipart/form-data' added to headers for all data.

<form action="/test" method="put" 
   onsubmit="Ajax.submit(event,data => console.log(data.response))">
   <input type="text" name="test" value="hello">
   <button type="submit">submit</button>
</form>

Readme

Keywords

Package Sidebar

Install

npm i als-ajax

Weekly Downloads

2

Version

4.0.0

License

ISC

Unpacked Size

3.68 kB

Total Files

3

Last publish

Collaborators

  • alexsorkin