src/core/Ajax.js
function (url, options, cb) {
        let postData;
        if (!isString(url)) {
            //for compatible
            //options, postData, cb
            const t = cb;
            postData = options;
            options = url;
            url = options.url;
            cb = t;
        } else {
            if (isFunction(options)) {
                const t = cb;
                cb = options;
                options = t;
            }
            options = options || {};
            postData = options.postData;
        }
        if (IS_NODE && Ajax.post.node) {
            options.url = url;
            return Ajax.post.node(options, postData, cb);
        }
        const client = Ajax._getClient(cb);
        client.open('POST', options.url, true);
        if (!options.headers) {
            options.headers = {};
        }
        if (!options.headers['Content-Type']) {
            options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
        }
        if ('setRequestHeader' in client) {
            for (const p in options.headers) {
                if (options.headers.hasOwnProperty(p)) {
                    client.setRequestHeader(p, options.headers[p]);
                }
            }
        }
        if (!isString(postData)) {
            postData = JSON.stringify(postData);
        }
        client.send(postData);
        return client;
    }
function (url, options, cb) {
        let postData;
        if (!isString(url)) {
            //for compatible
            //options, postData, cb
            const t = cb;
            postData = options;
            options = url;
            url = options.url;
            cb = t;
        } else {
            if (isFunction(options)) {
                const t = cb;
                cb = options;
                options = t;
            }
            options = options || {};
            postData = options.postData;
        }
        if (IS_NODE && Ajax.post.node) {
            options.url = url;
            return Ajax.post.node(options, postData, cb);
        }
        const client = Ajax._getClient(cb);
        client.open('POST', options.url, true);
        if (!options.headers) {
            options.headers = {};
        }
        if (!options.headers['Content-Type']) {
            options.headers['Content-Type'] = 'application/x-www-form-urlencoded';
        }
        if ('setRequestHeader' in client) {
            for (const p in options.headers) {
                if (options.headers.hasOwnProperty(p)) {
                    client.setRequestHeader(p, options.headers[p]);
                }
            }
        }
        if (!isString(postData)) {
            postData = JSON.stringify(postData);
        }
        client.send(postData);
        return client;
    }
function ( url , options , cb ) { let postData ; if ( ! isString ( url ) ) { //for compatible //options, postData, cb const t = cb ; postData = options ; options = url ; url = options . url ; cb = t ; } else { if ( isFunction ( options ) ) { const t = cb ; cb = options ; options = t ; } options = options || { } ; postData = options . postData ; } if ( IS_NODE && Ajax . post . node ) { options . url = url ; return Ajax . post . node ( options , postData , cb ) ; } const client = Ajax . _getClient ( cb ) ; client . open ( 'POST' , options . url , true ) ; if ( ! options . headers ) { options . headers = { } ; } if ( ! options . headers [ 'Content-Type' ] ) { options . headers [ 'Content-Type' ] = 'application/x-www-form-urlencoded' ; } if ( 'setRequestHeader' in client ) { for ( const p in options . headers ) { if ( options . headers . hasOwnProperty ( p ) ) { client . setRequestHeader ( p , options . headers [ p ] ) ; } } } if ( ! isString ( postData ) ) { postData = JSON . stringify ( postData ) ; } client . send ( postData ) ; return client ; }
Fetch remote resource by HTTP "POST" method
@param  {String}   url - resource url
@param  {Object}   options - request options
@param  {String|Object}  options.postData - post data
@param  {Object}   [options.headers=null]  - HTTP headers
@param  {Function} cb  - callback function when completed
@return {Ajax}  Ajax
@example
maptalks.Ajax.post(
'url/to/post',
{
postData : {
'param0' : 'val0',
'param1' : 1
}
},
(err, data) => {
if (err) {
throw new Error(err);
}
// do things with data
}
);
Fetch remote resource by HTTP POST method