如何使用jQuery上传图像,以便不必刷新页面? 所以我可以使用上传的图像。我不知道如何通过jQuery提交文件:/
如果我有以下表格
<form action = "myCurrentPage" method = "POST" enctype = "multipart/form-data">
<input type = "file" name = "LogoImage" id = "LogoImage">
</form>
答案 0 :(得分:0)
HTML:
<form id='myForm' onsubmit='doUpload()' action = "javascript:void(0)" method = "POST" enctype = "multipart/form-data">
<input type = "file" name = "LogoImage" id = "LogoImage">
</form>
使用Javascript:
function doUpload() {
var formData = new FormData(document.getElementById("myForm"));
$.ajax({
url: "/admin/scripts/addpet.php",
dataType: "xml",
type: "POST",
processData: false,
contentType: false,
data: formData
}).done(function(xmlDoc) {
});
}
在你的php端,你可以像往常一样抓取文件。 $ _FILES [ '文件名'] [ 'tmp_name的值']