2011-08-15 10 views
0

我知道這是一個典型的問題,但我已經嘗試了很多東西,並沒有得到它的工作。我有一個表單,我想要上載圖像,並且我已經瞭解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。

致以問候

+0

AJAX不處理文件。 –

回答

2

您無法序列化文件輸入。要異步上傳某些內容並使其適用於所有瀏覽器,您需要使用隱藏的iframe技巧。我建議找到一個jQuery插件。 Here is one you can try.

2

我建議你使用一些插件像uploadify

+0

2011年7月1日至2011年7月11日之間已下載Uploadify的用戶需要重新下載zip包。一些用戶告訴我,一些黑客能夠用一些粗略的代碼修改我的下載包。基本上,他們在uploadify.php文件的底部添加了一行代碼,可以通過電子郵件發送(http://www.uploadify.com/news/security-warning/) –