1. 程式人生 > >ajxa非同步傳輸檔案

ajxa非同步傳輸檔案

<form id="form1">
        <input type="file" name="file" />
    </form>

    <div class="click">
        提交
    </div>
    

    <script type="text/javascript">
        $('.click').click(function(){
            var formData = new FormData($( "#form1" )[0]);  
            $.ajax({  
                  url: './uploadclass.php' ,  
                  type: 'POST',  
                  data: formData,  
                  async: false,  
                  cache: false,  
                  contentType: false,  
                  processData: false,  
                  success: function (returndata) {  
                      alert(returndata);  
                  },  
                  error: function (returndata) {  
                      alert(returndata);  
                  }  
            });    
        })
    </script>