项目作者: BolajiAyodeji

项目描述 :
A simple AJAX Library for making HTTP Requests
高级语言: JavaScript
项目地址: git://github.com/BolajiAyodeji/simple-ajax-library.git
创建时间: 2019-04-05T12:03:23Z
项目社区:https://github.com/BolajiAyodeji/simple-ajax-library

开源协议:MIT License

下载


Getting Started

Download and include the JavaScript file | full version | minified | ES6 version |

  1. <script src="simpleAjax.js"></script>
  1. <script src="simpleAjax.min.js"></script>

Create a new simpleAjax

  1. const http = new simpleAJAX;

Examples

  • GET Request
  1. users = http.get('https://jsonplaceholder.typicode.com/users',
  2. (err, users) => {
  3. if(err) {
  4. console.log(err)
  5. } else {
  6. console.log(users);
  7. }
  8. });


  • POST Request
  1. const data = {
  2. "name": "Bolaji Ayodeji",
  3. "username": "bolajiayodeji",
  4. "email": "hi@bolajiayodeji.com",
  5. "address": {
  6. "street": "Hello world",
  7. "suite": "Hello",
  8. "city": "Lokoja, Kogi",
  9. "zipcode": "xxx-xxx-xxx",
  10. "geo": {
  11. "lat": "29.4572",
  12. "lng": "-164.2990"
  13. }
  14. },
  15. "phone": "+234 8109445504",
  16. "website": "https://bolajiayodeji.com",
  17. "company": {
  18. "name": "PhilanthroLab",
  19. "catchPhrase": "Multi-tiered zero tolerance productivity",
  20. "bs": "transition cutting-edge web services"
  21. }
  22. };
  23. http.post('https://jsonplaceholder.typicode.com/users',
  24. data, (err, user) => {
  25. if(err) {
  26. console.log(err)
  27. } else {
  28. console.log(user);
  29. }
  30. });


  • PUT Request
  1. const data = {
  2. "name": "Bolaji Ayodeji",
  3. "username": "bolajiayodeji",
  4. "email": "hi@bolajiayodeji.com",
  5. "address": {
  6. "street": "Hello world",
  7. "suite": "Hello",
  8. "city": "Lokoja, Kogi",
  9. "zipcode": "xxx-xxx-xxx",
  10. "geo": {
  11. "lat": "29.4572",
  12. "lng": "-164.2990"
  13. }
  14. },
  15. "phone": "+234 8109445504",
  16. "website": "https://bolajiayodeji.com",
  17. "company": {
  18. "name": "PhilanthroLab",
  19. "catchPhrase": "Multi-tiered zero tolerance productivity",
  20. "bs": "transition cutting-edge web services"
  21. }
  22. };
  23. http.put('https://jsonplaceholder.typicode.com/users/1',
  24. data, (err, user) => {
  25. if(err) {
  26. console.log(err)
  27. } else {
  28. console.log(user);
  29. }
  30. });


  • DELETE Request
  1. users = http.delete('https://jsonplaceholder.typicode.com/users/1',
  2. (err, response) => {
  3. if(err) {
  4. console.log(err)
  5. } else {
  6. console.log(response);
  7. }
  8. });

Demo

Demo here

Contribution Guide

  1. git clone https://github.com/BolajiAyodeji/simple-ajax-library.git
  1. cd simple-ajax-library
  1. npm install
  1. npm run build