您可以进行一些更改以适合需要,但是如果您需要进度条,则效果会很好。您可以添加更多事件监听器,并根据需要进行设置。希望这对您来说是一个很好的起点。
function uploadFile(){ var file = document.getElementById("zip_file").files[0]; var formdata = new FormData(); formdata.append("zip_file", file); var ajax = new XMLHttpRequest(); ajax.upload.addEventListener("progress", function(event) { runprogress(event); } , false); ajax.addEventListener("load", function(event) {uploadcomplete(event); }, false); //Target your php file. ajax.open("POST", "upload.php"); ajax.send(formdata);}function runprogress(event){ //The progress %, you might want to Math.round(percent) var percent = (event.loaded / event.total) * 100;}function uploadcomplete(event){ //This will = to your php reply. var AjaxReply=event.target.responseText;}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)