Class: Ajax

Ajax

Ajax Utilities in both Browser and Node. It is static and should not be initiated.

new Ajax() [source]


Static Methods

  • (static) get(url, cb) [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
    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) getJSON(url, callback) [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);
        }
    );
    Parameter Type Description
    url String json's url
    callback function callback function when completed.