Skip to content

yunisdev/AjaxSimpler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AjaxSimplier

Installation

Install with npm:

$ npm i ajaxsimpler

Or, use from unpkg.com:

<script src="https://unpkg.com/ajaxsimpler"></script>

You also need to add Jquery (for AJAX) before ajaxsimpler. So, you can use this imports for HTML file:

<script src="https://unpkg.com/jquery"></script>
<script src="https://unpkg.com/ajaxsimpler"></script>

Usage

Creating object and setup

To use Ajax Simpler, you must create object first:

var ajx = window.AjaxSimpler.create();

If you are using a backend application, ex. Django, you will need to add CSRF token. For adding CSRF token, you can add:

ajx.csrftoken = "csrftoken";

For example, if your app has CSRF token in cookie with different name you should use:

ajx.csrftoken = "COOKIE_NAME";

Also for shorthand, you can add CSRF token when creating object:

var ajx = window.AjaxSimpler.create({ csrftoken: "csrftoken" });

For adding default headers, you can use:

ajx.addDefaultHeader("Content-Type", "application/json");

For deleting default header:

ajx.deleteDefaultHeader("Content-Type");

Requests

For GET request you can use:

ajx.GET("URL_HERE").then((result) => console.log(result));

AjaxSimpler.GET returns Promise object. Accepts, 3 parameters:

  • url (required) URL to request.
  • data Data to send as url parameter.
  • header Headers for request.

For POST request you can use:

ajx.POST("URL_HERE").then((result) => console.log(result));

AjaxSimpler.POST returns Promise object. Accepts, 3 parameters:

  • url (required) URL to request.
  • data Data to send as request body.
  • header Headers for request.
Thanks for using AjaxSimpler