前一篇記錄AJAX  送出FORM . 

但是, 在上傳檔案時, 卻一直抓不到資料, 改成這樣後就可以了.   

寫個記錄. 我可是試好久才試出來的呢~~~~ (淚) 


<form class="form-horizontal" method="post" action="admin.php?action=processlogo" enctype="multipart/form-data" onSubmit="return senddata();">
                                                  
    <div class="form-group">
        <label class="control-label col-sm-2">請上傳圖片</label>
        <div class="col-sm-6"><input type="file" name="userfile" class="form-control"></div>        
    </div>
     
    <div class="col-sm-2"></div>
    <div class="col-sm-6"><button type="submit" class="button button-3d nomargin">上傳更換LOGO</button></div>
    
    
      
</form>



<script> 


function senddata() {                
                var formData = new FormData($('form')[0]);
                $.ajax({ // create an AJAX call...                    
                    async: false,
                    cache: false,
                    contentType: false,
                    processData: false,
                    data: formData, // get the form data
                    type: $('form').attr('method'), // GET or POST                  
                    url: $('form').attr('action'), // the file to call
                    success: function(response) { // on success..kalert('333');
                        $("#msgdiv").fadeIn('slow');
                        $("#msgstr").html(response);
                    }
                });
                return false;

     }

</scirpt> 



arrow
arrow
    文章標籤
    AJAX  FORM  jquery  upload
    全站熱搜

    peeress 發表在 痞客邦 留言(0) 人氣()