【发布时间】:2011-08-15 14:28:25
【问题描述】:
我知道这是一个典型的问题,但我已经尝试了很多东西,但还没有让它起作用。我有一个要上传图像的表单,并且据我了解,jquery 本机不支持表单提交中的图像上传。所以我们从我拥有的 html 开始:
<form action="uploadImage.php" method="post" enctype="multipart/form-data" id="image_form" name="image_form">
<input type="file" name="addImage" />
<input type="submit" name="submit" value="submit" />
</form>
<div id="results">
</div>
然后我们有了javascript:
$(document).ready(function() {
$('#image_form').submit(function() { // catch the form's submit event
$.ajax({ // create an AJAX call...
data: $(this).serialize(), // get the form data
type: $(this).attr('method'), // GET or POST
url: $(this).attr('action'), // the file to call
success: function(response) { // on success..
$('#results').load('Images.php'); // update the DIV
}
});
return false; // cancel original event to prevent form submitting
});
});
有些东西告诉我我需要一个 http://malsup.com/jquery/ 的实现,但我真的不明白怎么做。我的图片上传 php 脚本运行良好而且很棒,所以如果我可以使用表单操作但使用 jquery 提交它会很酷。
最好的问候
【问题讨论】:
标签: php jquery file-upload