<form id="uploadForm"> <p>上传文件:<input type="file" name="file" /></p> <input type="button" value="上传" onclick="upload()" /> </form> function upload() { var formData = new FormData($("#uploadForm")[0]); $.ajax({ url: '', type: 'POST', data: formData, async: false, cache: false, contentType: false, processData: false, success: function(data) { }, error: function(data) { } }); }
需要使用
async: false