Mam dwa ajax połączeń i wzywam ich async
:Dwa asynchroniczny AJAX wzywa powraca sam wynik
xmlhttpPostInstagram2('firsturl');
xmlhttpPostInstagram3('secondurl');
Problemem jest to, że otrzymuję takie same wyniki z obu połączeń. Jeśli zmienię async
na synchronizację, otrzymuję dwa różne wyniki, które są oczekiwane. Czy którykolwiek punkt, który psuje połączenie ajax async
?
Nie chcę używać jquery. javascript odpowiedź byłaby doceniona.
function xmlhttpPostInstagram2(strURL) {
var originalValue = ""
var xmlHttpReq = false;
var self = this;
// Mozilla/Safari
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
self.xmlHttpReq.open('POST', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
var temp2 = document.getElementById('sidebartag');
temp2.innerHTML = self.xmlHttpReq.responseText; // child is the fetched string from ajax call in your case
}
}
self.xmlHttpReq.send();
}
i
function xmlhttpPostInstagram3(strURL) {
var originalValue = ""
var xmlHttpReq = false;
var self = this;
// Mozilla/Safari
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
// IE
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
self.xmlHttpReq.open('POST', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
var temp2 = document.getElementById('sidebartag1');
temp2.innerHTML = self.xmlHttpReq.responseText; // child is the fetched string from ajax call in your case
}
}
self.xmlHttpReq.send();
}
Myślę, że problem jest kwestia określania zakresu. Sprawdź moją odpowiedź i sprawdź, czy to pomaga? –