http request and response react code example
Example 1: http request javascript
function httpGetAsync(url, callback) {
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", url, true);
xmlHttp.send(null);
}
Example 2: callback in response node.js
function longRunningFunction(param1, callback){
setTimeout(function(){
var results="O High there!";
callback(results);
}, 2000);
}
longRunningFunction("morning", function(result){
alert(result);
});