1.0.5 • Published 4 years ago
@lorndev/ajax v1.0.5
This package provide helper to perform Ajax requests GET and POST.
Install
To install package, run npm install @lorndev/ajax
.
After install import JS class in your application.
JS
import { Ajax } from '@lorndev/Ajax/Ajax';
Usage
Example to post JSON content.
// Method (GET,POST...)
const method = 'POST';
// Your body content (Can be a buffer, string...)
const body = JSON.stringify({ message: 'Hello World' });
// Url
const url = 'http://localhost';
// Url parameters
const params = { 'count': 3 };
// Headers
const headers = { 'Content-Type': 'application/json' };
// Callback must be a function
const callback = (error,status,body) => {
if (!error) {
//...code
} else {
//...code
}
}
// Body, Params and Headers is optional.
new Ajax().request(method,url,callback,body,params,headers);