ich zwei ajax Anrufe und ich rufe sie async
:Zwei Asynchron-AJAX-Aufrufe kehren gleiches Ergebnis
xmlhttpPostInstagram2('firsturl');
xmlhttpPostInstagram3('secondurl');
Das Problem ist, ich die gleichen Ergebnisse aus beiden Anrufen immer bin. Wenn ich async
ändere, um zu synchronisieren, erhalte ich zwei verschiedene Ergebnisse, die die erwartete sind. Kann irgendjemand zeigen, was den Ajax async
Anruf verwirren?
Ich möchte nicht jquery verwenden. javascript Antwort würde geschätzt werden.
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();
}
und
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();
}
Ich denke, Ihr Problem ein Scoping-Problem. Überprüfen Sie meine Antwort und sehen Sie, ob es hilft? –