日期:2014-05-16 浏览次数:20499 次
$( function() { var progressBar = document.querySelector("#progressBar"); var file = document.querySelector("#file"); file.onchange = function(){ };//onchange $("#MainBoard #submit").click( function(){ if(file.files[0]) { $("#progressBar").css("display","inline"); $("#MainBoard input").attr("disabled","disabled"); var xhr = new XMLHttpRequest(); if(xhr) { xhr.open('POST','mySpace_addFile.php'); //soit utilise xhr.onreadystatechange if(xhr.readyState == 1)//1==Opened { xhr.onload = function(){ if(xhr.readyState==4) alert("Upoload over"); else alert("Error in upload"); $("#progressBar").css("display","none"); $("#MainBoard input").removeAttr("disabled"); };//onload xhr.upload.onprogress = function(e){ progressBar.value = e.loaded; progressBar.max = e.total; };//onprogres var form = new FormData(); form.append('new_file', file.files[0]);//这个是文件,应该在$_FILES里 form.append('anti_multipl',$("anti_multipl").val());//这个是变量,应该在$_POST里 xhr.send(form); }else{ alert("Cannot open server for upload"); } } } });//click });//ready