我想将一个带有javascript的文件发送到php文件。
我的 php 文件中有这个表单
<form action="" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file1"><br>
<p id="poi">upload</p>
<p id="plo"></p>
</form>
并在JS文件中白化此代码
jQuery(document).on("click","#poi",function(){
var objfile=new FormData();
var file=jQuery("#file1").get(0).files[0];
objfile.append("iefile078",file);
var ajax ;
ajax.upload.addEventListener("progress" ,progresshandler ,false);
function progresshandler(){
jQuery("#plo").text("uploading ....");
}
ajax.open("POST","helper.php");
ajax.send(objfile);
});
当我单击页面上的"上传"时,此功能正确触发。
我想在上传正在进行"上传...."显示给用户。
另外,我想将此文件发送到助手.php文件。
在这种情况下,如何将 open() 和 send() 函数的属性设置为将上传到帮助程序的文件传递到.php?
这是我的文件结构和我的表单默认位置.php
js
jquery.js
tmpl
default.php
helper.php
mod_upload.php
mod_upload.xml
试试这个:
$(document).on("click","#poi", function(e) {
e.preventDefault();
var formData = new FormData($(this)[0]);
$.ajax({
url: 'helper.php',
type: 'POST',
data: formData,
async: false,
beforeSend: function() {
$("#message1").show().html("uploading...");
},
success: function(data) {
$("#message1").fadeOut();
$("#container").html(data);
},
cache: false,
contentType: false,
processData: false
});
});