1.2.0 • Published 3 years ago

ajaxsimpler v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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
1.2.0

3 years ago

1.1.1

3 years ago

1.1.0

3 years ago