Skip to main content

dg-ajax

DG.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();

Methods

MethodReturnsDescription
DG.ajax( <String> url, <Ajax options> options? ) PromiseSends 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.

Options

OptionTypeDefaultDescription
dataObjectnullThe data that will be sent to the server.
typeStringgetType of request ('get', 'post' or 'jsonp').
successFunctionnullA function which is triggered in case of successful server response. Takes the received data as a parameter.
errorFunctionnullA function that is triggered when an error occurs. Takes the error information as a parameter.
urlStringnullThe URL to which the request will be sent.
timeoutNumbernullQuery timeout (in milliseconds).