Here's a snippet of my basic web page:
<!DOCTYPE html>
<html>
<head>
</head>
<body onload="start()">
</body>
</html>
Below is the XMLHttpRequest function I've implemented:
function start(){
//Defining the httpRequest variable
var httpRequest;
//Creating an instance compatible with multiple browsers
if (window.XMLHttpRequest) { // For Mozilla, Safari, ...
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject){ // For Internet Explorer 8 and older versions
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
//Specifying what to do upon receiving response
httpRequest.onreadystatechange = httpResult;
httpRequest.open("GET","http://data.mtgox.com/api/2/BTCUSD/money/ticker_fast?pretty", true);
httpRequest.send();
function httpResult(){
if (httpRequest.readyState === 4 && httpRequest.status === 200){
alert(httpResult.responseText);
} else {
alert("An issue occurred while making the request");
}
}
}
Upon loading the web page, the function executes but triggers the "problem making request" alert thrice. No errors are showing up in the JavaScript console. Any insights on why the expected response isn't being received?