4.0.0 • Published 2 years ago
als-ajax v4.0.0
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>