Ajax

Go back to Scripts

Click on "make request" and check the console for the response.

GET

new ML.Ajax({
responseType: 'json',
url: 'https://reqres.in/api/users/2',
success: function(xhr) {
console.log(xhr.response.data);
},
error: function(xhr) {
console.log('ERROR', xhr);
}
});

POST

new ML.Ajax({
url: 'https://reqres.in/api/users',
method: 'POST',
responseType: 'json',
data: {
name: 'john smith',
age: 22
}
success: function(xhr) {
console.log(xhr.response);
},
error: function(xhr) {
console.log('ERROR', xhr);
}
});

JSONP

var callbackFunction = function(response) {
console.log(response);
};

new ML.Ajax({
url: 'https://jsfiddle.net/echo/jsonp',
method: 'JSONP',
data: {
name: 'john smith',
age: 22
},
jsonpCallback: 'callbackFunction'
});

Notes