This repository has been archived by the owner on Aug 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
ajax
Eser Ozvataf edited this page May 21, 2015
·
6 revisions
$l.ajax.corsDefault = true;
Usage: $l.ajax.get(path[, values, cors])
// url: /listUsers
$l.ajax.get('/listUsers').done(
function(response) {
console.log(response);
}
);
// url: /getUser?userId=5&allDetails=true
$l.ajax.get(
'/getUser',
{ userId: 5, allDetails: true }
).done(
function(response) {
console.log(response);
}
);
Usage: $l.ajax.getJson(path[, values, cors])
// url: /listUsers
$l.ajax.getJson('/listUsers').done(
function(response) {
console.log(response);
}
);
Usage: $l.ajax.post(path[, values, cors])
$l.ajax.post(
'/login',
{ username: 'me', password: 'xxx', rememberme: true }
).done(
function(response) {
console.log(response);
}
);
Usage: $l.ajax.post(path[, values, cors])
var formData = new FormData();
formData.append('fullname', 'Laroux Blackmore');
formData.append('profilepicture', fileInputElement.files[0]);
$l.ajax.post('/updateProfile', formData).done(
function(response) {
console.log(response);
}
);
Usage: $l.ajax.postJson(path[, values, cors])
$l.ajax.postJson(
'/login',
{ username: 'me', password: 'xxx', rememberme: true }
).done(
function(response) {
console.log(response);
}
);
Usage: $l.ajax.getScript(path[, values, cors])
$l.ajax.getScript(
'http://www.foo.com/bar.js'
);
Usage: $l.ajax.getJsonP(path, values, method[, cors])
function getMemberData(data) {
console.log(data);
}
$l.ajax.getJsonP(
'http://www.foo.com/bar.jsonp',
{ memberId: 5 },
'getMemberData'
);
Usage: $l.ajax.makeRequest({type: type, url: url, datatype: datatype, getdata: getdata, postdata: postdata, postdatatype: postdatatype, header: headers, cors: cors, jsonp: jsonp})
$l.ajax.makeRequest({
type: 'POST',
url: '/ajax-request-url',
datatype: 'json',
postdata: { username: 'me', password: 'xxx', rememberme: true },
postdatatype: 'form',
cors: true,
headers: { 'X-Requested-With': 'XMLHttpRequest' }
}).done(
function(response) {
console.log('success', response);
}
).fail(
function(err) {
console.log('failed', err);
}
);
Please don't hesitate to submit issues and pull requests.