4.0.2 • Published 6 years ago

ajax-class v4.0.2

Weekly downloads
27
License
MIT
Repository
github
Last release
6 years ago

usage

    let xhr = new Ajax();
    // or
    let xhr = new Ajax('get', 'www.example.com', true);

    // offer many properties and methods that you can control Ajax instance

properties

    static defaults: {
        [key: string]: string | boolean | number;
    };
    readonly xhr: XMLHttpRequest;
    readonly readyState: string;
    readonly status: number;
    readonly statusMessage: string;
    readonly response: any;
    body: ArrayBuffer | Blob | string | {
        [key: string]: any
    } | FormData | HTMLFormElement;
    method: string;
    url: string;
    responseType: string;
    charset: string;
    async: boolean;
    headers: {
        [key: string]: string
    };
    length: number;
    events: {
        [key: string]: (event: Event) => void;
    };
    timeout: number;
    query: string;
    queryUsed: boolean;
    bodyUsed: boolean;
    options: (ops: object) => void;
    getResponseHeadaer: (key: string) => string;
    on: (ev: string, fn: (event: Event) => void) => void;
    abort: () => void;
    fetch: () => Promise<any>;

methods

    // shortname of above properties setting
    options: (ops: object) => void;
    getResponseHeadaer: (key: string) => string;
    on: (ev: string, fn: (event: Event) => void) => void;
    abort: () => void;
    fetch: () => Promise;

Attention please, if you want to use get method, using query instead of body

// you want to get some data from http://www.example.com?name=DoubleDimos&age=22

// codes below will not work correct
async getData() {
    let ajax = new Ajax('get', 'http://www.example.com', true);
    ajax.body = {
        name: 'Double Dimos',
        age: 22
    };
    return await ajax.fetch();
}

// using this instead

async getData() {
    let ajax = new Ajax('get', 'http://www.example.com', true);
    ajax.query = {
        name: 'Double Dimos',
        age: 22
    };
    return await ajax.fetch();
}
4.0.2

6 years ago

4.0.1

6 years ago

3.0.4

6 years ago

3.0.3

6 years ago

3.0.2

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago