Is there a different way to write code for making ajax calls for two pages within a single function? Also, I am looking for a method to compare the responses from both requests, specifically comparing objects y2 and y3.
function compareResponses() {
alert('comp');
// Getting object of ORIGINAL data
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
y = xmlhttp.responseText;
alert(y);
y2 = JSON.parse(y);
}
}
xmlhttp.open("POST", "2.ashx", true);
xmlhttp.setRequestHeader("content-type", "application/x-www-form-urlencoded");
xmlhttp.send();
// Getting object of another data
if (window.XMLHttpRequest) {
xmlhttp1 = new XMLHttpRequest();
} else {
xmlhttp1 = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp1.onreadystatechange = function () {
if (xmlhttp1.readyState == 4 && xmlhttp1.status == 200) {
y1 = xmlhttp1.responseText;
//alert(y1);
y3 = JSON.parse(y1);
}
xmlhttp1.open("POST", "1.ashx", true);
xmlhttp1.setRequestHeader("content-type", "application/x-www-form-urlencoded");
xmlhttp1.send();
}