Created
May 31, 2018 22:57
-
-
Save SalesforceBobLightning/a56ce2e9b5acff7a7a632a367bb272bf to your computer and use it in GitHub Desktop.
JavaScript Ajax Request in Salesforce Lightning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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