Мой AJAX код выглядит следующим образом:запрос Http посылает 2 раза через AJAX
data = new FormData();
// data="";
paths = "";
// Create a new HTTP requests, Form data item (data we will send to the server) and an empty string for the file paths.
xhr = new XMLHttpRequest();
// Set how to handle the response text from the server
xhr.onreadystatechange = function(ev){
//console.debug(xhr.responseText);
// console.log("success"+xhr.responseText);
try{
console.log($.parseJSON(xhr.responseText));
var data=$.parseJSON(xhr.responseText);
if(data.success=="yes"){
projectCounter++;
var projectName=$.parseJSON(data.arguments);
console.log(projectName.projectName);
console.log('update table');
if(projectCounter==2){
UploadComplete(projectName.projectName);
}
}
}
catch(e){}
};
// Loop through the file list
for (var i in files){
// Append the current file path to the paths variable (delimited by tripple hash signs - ###)
paths += files[i].webkitRelativePath+"###";
// Append current file to our FormData with the index of i
data.append(i, files[i]);
};
// Append the paths variable to our FormData to be sent to the server
// Currently, As far as I know, HTTP requests do not natively carry the path data
// So we must add it to the request manually.
data.append('paths', paths);
// console.log(paths);
// Open and send HHTP requests to upload.php
xhr.open('POST', "upload.php", true);
console.log(data);
xhr.send(this.data);
вопрос я столкнулся в том, что он отправляющий запрос HTTP 2 раза. Я получаю ответ Http 2 раза. Я написал console.log («Таблица обновлений»), и он показывает 2 раза. Я очень смущен, почему я получаю 2 ответа Http вместо того, что я отправляю только 1 запрос?
возможно, чтобы показать контекст которой работает этот код? – melc
melc отправляет запрос upload.php, который загружает скрипт upload.php данных. я проверил его –