我知道這是一個典型的問題,但我已經嘗試了很多東西,並沒有得到它的工作。我有一個表單,我想要上載圖像,並且我已經瞭解jquery natively doesent在表單提交中支持imageupload。因此,我們開始與HTML我有:上傳圖像與jQuery和顯示結果
<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/的implentation,但我真的不知道怎麼樣。而我的PHP腳本的圖片上傳工作正常,很好,所以它會很酷,如果我只是可以使用表單操作,但提交與jQuery。
致以問候
AJAX不處理文件。 –