https://github.com/yunisdev/ajaxsimpler
Simplified AJAX syntax
https://github.com/yunisdev/ajaxsimpler
Last synced: 9 months ago
JSON representation
Simplified AJAX syntax
- Host: GitHub
- URL: https://github.com/yunisdev/ajaxsimpler
- Owner: yunisdev
- Created: 2021-03-17T13:05:25.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-04-01T09:50:14.000Z (about 5 years ago)
- Last Synced: 2025-08-05T11:34:32.351Z (11 months ago)
- Language: JavaScript
- Homepage:
- Size: 67.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AjaxSimplier
### Installation
Install with npm:
```bash
$ npm i ajaxsimpler
```
Or, use from unpkg.com:
```html
```
You also need to add Jquery (for AJAX) before ajaxsimpler. So, you can use this imports for HTML file:
```html
```
### Usage
#### Creating object and setup
To use Ajax Simpler, you must create object first:
```js
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:
```js
ajx.csrftoken = "csrftoken";
```
For example, if your app has CSRF token in cookie with different name you should use:
```js
ajx.csrftoken = "COOKIE_NAME";
```
Also for shorthand, you can add CSRF token when creating object:
```js
var ajx = window.AjaxSimpler.create({ csrftoken: "csrftoken" });
```
For adding default headers, you can use:
```js
ajx.addDefaultHeader("Content-Type", "application/json");
```
For deleting default header:
```js
ajx.deleteDefaultHeader("Content-Type");
```
#### Requests
For `GET` request you can use:
```js
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:
```js
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