https://github.com/droidninja/reqwrapper
ajax wrapper for handling all types of POST (form-encoded,json,multipart) and GET request without jquery
https://github.com/droidninja/reqwrapper
Last synced: 2 months ago
JSON representation
ajax wrapper for handling all types of POST (form-encoded,json,multipart) and GET request without jquery
- Host: GitHub
- URL: https://github.com/droidninja/reqwrapper
- Owner: DroidNinja
- License: mit
- Created: 2016-08-20T06:31:40.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-08-20T07:12:03.000Z (almost 10 years ago)
- Last Synced: 2026-03-11T11:55:16.243Z (3 months ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# reqWrapper
ajax wrapper for handling all types of POST (form-encoded,json,multipart) and GET request without jquery
# Installation
```sh
$ bower install reqWrapper
```
# Usage
**GET Request**
`request.get(url, )`
```javascript
request.get('', null)
.success(function(response, xhr){
console.log(response);
})
.error(function(message, xhr){
console.log(message);
})
.always(function(){
console.log('always');
}).execute();
```
**POST (form-urlencoded) Request**
`request.post(url, , )`
```javascript
request.post('', {
"username" : "droidninja",
"password" : "password"
}, null)
.success(function(response, xhr){
console.log(generateFootfallPerDayJson(response));
})
.error(function(message, xhr){
console.log(message);
})
.always(function(){
console.log('always');
}).execute();
```
**POST (application/json) Request**
```javascript
request.post('', {
"username" : "droidninja",
"password" : "password"
}, null)
.isJsonType()
.success(function(response, xhr){
console.log(generateFootfallPerDayJson(response));
})
.error(function(message, xhr){
console.log(message);
})
.always(function(){
console.log('always');
}).execute();
```
**POST (multipart-formdata) Request**
```javascript
var fileObj = document.getElementById("myFileField").files[0];
request.post('', {
profilePic: fileObj,
userId: 9
}, null)
.setHeaders({
"X-Access-Token" : ""
})
.isMultipartType()
.success(function(response, xhr){
console.log(response);
})
.error(function(message, xhr){
console.log(message);
})
.always(function(){
console.log('always');
}).execute();
```
You can include `setHeaders()` with any type of request to set custom headers.