Skip to content

Instantly share code, notes, and snippets.

@SalesforceBobLightning
Created May 31, 2018 22:57
Show Gist options
  • Save SalesforceBobLightning/a56ce2e9b5acff7a7a632a367bb272bf to your computer and use it in GitHub Desktop.
Save SalesforceBobLightning/a56ce2e9b5acff7a7a632a367bb272bf to your computer and use it in GitHub Desktop.
JavaScript Ajax Request in Salesforce Lightning
callAjax : function(method, url, async, callback) {
var request = new XMLHttpRequest();
request.onreadystatechange = function(component) {
if (request.readyState == 4 ) {
callback.call(this, request);
}
};
request.open(method, url, async);
request.send();
},
makeAjaxRequest : function(component, url) {
this.callAjax("GET", url, true,
function(response)
{
if (response.status == 200) {
var data = response.responseText;
}
else if (response.status == 400) {
console.log("AjaxRequest: 400 Error");
}else {
console.log("AjaxRequest: Error");
}
}
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment