我正在尝试上传多个文件
我正在使用ajax
问题是有时上传无效
我不确定reload函数reloadtabeladeanexos()
上传后我正在对mysql进行查询并在html表上显示上传的文件名和URL
在我的电脑中我正在使用chrome并且有效,但有时当我打开一个新表单时,如果我重新加载mannualy并且再次尝试上传效果很好的话,第一次无法上传
function reloadtabeladeanexos() {
// location.reload();
$.ajax({
url: window.location.href,
headers: {
"Pragma": "no-cache",
"Expires": -1,
"Cache-Control": "no-cache"
}
}).done(function () {
window.location.reload(true);
});
}
function uploadFile(){
var input = document.getElementById("file1");
for (i = 0; i < input.files.length; i++) {
//alert(input.files.length);
var file = _("file1").files[i];
var idc =<?php echo $pid; ?>;
var ponto=16;
var iddoafme=<?php echo $r_id; ?>;
// alert(<?php echo $pid; ?>);
//alert(ponto);
//alert(file.name+" | "+file.size+" | "+file.type);
var formdata = new FormData();
formdata.append("file1", file);
formdata.append("idc", idc);
formdata.append("ponto", ponto);
formdata.append("iddoafme", iddoafme);
var ajax = new XMLHttpRequest();
ajax.upload.addEventListener("progress", progressHandler, false);
ajax.addEventListener("load", completeHandler, false);
ajax.addEventListener("error", errorHandler, false);
ajax.addEventListener("abort", abortHandler, false);
//ajax.open("POST", "upload.php?idc="+$r_idc+");
ajax.open("POST", "uploadponto16.php");
ajax.send(formdata);
reloadtabeladeanexos();
}
}
function progressHandler(event){
_("loaded_n_total").innerHTML = "Uploaded "+event.loaded+" bytes of "+event.total;
var percent = (event.loaded / event.total) * 100;
_("progressBar").value = Math.round(percent);
_("status").innerHTML = Math.round(percent)+"% uploaded... please wait";
}
function completeHandler(event){
_("status").innerHTML = event.target.responseText;
_("progressBar").value = 0;
reloadtabeladeanexos();
}
function errorHandler(event){
_("status").innerHTML = "Upload Failed";
}
function abortHandler(event){
_("status").innerHTML = "Upload Aborted";
}