• HTML:  

<form id= "uploadForm">  

    <>指定文件名: <input type="text" name="filename" value= ""/></>  

    <>上传文件: <input type="file" name="file"/></ p>  

    <input type="button" value="上传" onclick="doUpload()" />  

</form>  

  • JS:

function doUpload() {  

var formData = new FormData($( "#uploadForm" )[0]);  

     $.ajax({  

          url: 'xxx' ,                  --------------这里是请求的接口

          type: 'POST',              

          data: formData,  

          async: false,  

          cache: false,  

          contentType: false,  

          processData: false,  

          success: function (returndata) {  

              alert(returndata);  

          },  

          error: function (returndata) {  

              alert(returndata);  

          }  

     });  

posted on 2017-05-24 13:13  糖I果  阅读(739)  评论(0编辑  收藏  举报