Class: Ajax

Ajax

Ajax Utilities. It is static and should not be initiated.

new Ajax() [source]


Static Methods

  • (static) jsonp(url, cb) [source]

  • Get JSON data by jsonp from https://gist.github.com/gf3/132080/110d1b68d7328d7bfe7e36617f7df85679a08968
    Parameter Type Description
    url String resource url
    cb function callback function when completed

  • (static) get(url, cb, options) [source]

  • Fetch remote resource by HTTP "GET" method
    maptalks.Ajax.get(
        'url/to/resource',
        (err, data) => {
            if (err) {
                throw new Error(err);
            }
            // do things with data
        }
    );
    Parameter Type Description
    url String resource url
    cb function callback function when completed
    options Object request options
    Properties
    Parameter Type Description
    headers Object HTTP headers
    responseType String responseType
    credentials String if with credentials, set it to "include"
    Returns:
    Ajax: Ajax
  • (static) post(options, postData, cb) [source]

  • Fetch remote resource by HTTP "POST" method
    maptalks.Ajax.post(
        {
            'url' : 'url/to/post'
        },
        {
            'param0' : 'val0',
            'param1' : 1
        },
        (err, data) => {
            if (err) {
                throw new Error(err);
            }
            // do things with data
        }
    );
    Parameter Type Description
    options Object post options
    Properties
    Parameter Type Description
    url String url
    headers Object HTTP headers
    postData String | Object data post to server
    cb function callback function when completed
    Returns:
    Ajax: Ajax
  • (static) getArrayBuffer(url, callback, options) [source]

  • Fetch resource as arraybuffer.
    maptalks.Ajax.getArrayBuffer(
        'url/to/resource.bin',
        (err, data) => {
            if (err) {
                throw new Error(err);
            }
            // data is a binary array
        }
    );
    Parameter Type Description
    url String url
    callback function callback function when completed.
    options Object

  • (static) getJSON(url, callback, options) [source]

  • Fetch resource as a JSON Object.
    maptalks.Ajax.getJSON(
        'url/to/resource.json',
        (err, json) => {
            if (err) {
                throw new Error(err);
            }
            // json is a JSON Object
            console.log(json.foo);
        },
        { jsonp : true }
    );
    Parameter Type Description
    url String json's url
    callback function callback function when completed.
    options Object optional options
    Properties
    Parameter Type Description
    jsonp String fetch by jsonp, false by default