Getting Started
Download and include the JavaScript file | full version | minified | ES6 version |
<script src="simpleAjax.js"></script>
<script src="simpleAjax.min.js"></script>
Create a new simpleAjax
const http = new simpleAJAX;
Examples
- GET Request
users = http.get('https://jsonplaceholder.typicode.com/users',
(err, users) => {
if(err) {
console.log(err)
} else {
console.log(users);
}
});
- POST Request
const data = {
"name": "Bolaji Ayodeji",
"username": "bolajiayodeji",
"email": "hi@bolajiayodeji.com",
"address": {
"street": "Hello world",
"suite": "Hello",
"city": "Lokoja, Kogi",
"zipcode": "xxx-xxx-xxx",
"geo": {
"lat": "29.4572",
"lng": "-164.2990"
}
},
"phone": "+234 8109445504",
"website": "https://bolajiayodeji.com",
"company": {
"name": "PhilanthroLab",
"catchPhrase": "Multi-tiered zero tolerance productivity",
"bs": "transition cutting-edge web services"
}
};
http.post('https://jsonplaceholder.typicode.com/users',
data, (err, user) => {
if(err) {
console.log(err)
} else {
console.log(user);
}
});
- PUT Request
const data = {
"name": "Bolaji Ayodeji",
"username": "bolajiayodeji",
"email": "hi@bolajiayodeji.com",
"address": {
"street": "Hello world",
"suite": "Hello",
"city": "Lokoja, Kogi",
"zipcode": "xxx-xxx-xxx",
"geo": {
"lat": "29.4572",
"lng": "-164.2990"
}
},
"phone": "+234 8109445504",
"website": "https://bolajiayodeji.com",
"company": {
"name": "PhilanthroLab",
"catchPhrase": "Multi-tiered zero tolerance productivity",
"bs": "transition cutting-edge web services"
}
};
http.put('https://jsonplaceholder.typicode.com/users/1',
data, (err, user) => {
if(err) {
console.log(err)
} else {
console.log(user);
}
});
- DELETE Request
users = http.delete('https://jsonplaceholder.typicode.com/users/1',
(err, response) => {
if(err) {
console.log(err)
} else {
console.log(response);
}
});
Demo
Demo here
Contribution Guide
git clone https://github.com/BolajiAyodeji/simple-ajax-library.git
cd simple-ajax-library
npm install
npm run build