Asynchronous requests (AJAX) | RasterJS API | Urbi Documentation
RasterJS API

Asynchronous requests (AJAX)

The DG.ajax function allows to send cross-domain AJAX requests.

var promise = DG.ajax('http://www.geonames.org/postalCodeLookupJSON', {
    type: 'get',
    data: {
        postalcode: 10504,
        country: 'US',
    },
    success: function (data) {
        console.log('success', data);
    },
    error: function (error) {
        console.log('error', error);
    },
});

// to cancel the request:
// promise.abort();
Method Returns Description
DG.ajax( <String> url, <Ajax options> options? ) Promise Sends a request to the server and returns a Promise object with the abort method, with the help of which you can abort the sending of the request. Takes a URL as input parameters, where we will send you a request and an optional object of options.
Option Type Default Description
data Object null The data that will be sent to the server.
type String get Type of request ('get', 'post' or 'jsonp').
success Function null A function which is triggered in case of successful server response. Takes the received data as a parameter.
error Function null A function that is triggered when an error occurs. Takes the error information as a parameter.
url String null The URL to which the request will be sent.
timeout Number null Query timeout (in milliseconds).