Created
August 9, 2017 04:00
-
-
Save johnsonz/42b71eb86c2e87d38fb85cd73c473fb8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//form方式 | |
<form id="uploadForm" enctype="multipart/form-data"> | |
<input id="file" type="file" name="file"/> | |
<button id="upload" type="button">upload</button> | |
</form> | |
$.ajax({ | |
url: '/upload', | |
type: 'POST', | |
cache: false, | |
data: new FormData($('#uploadForm')[0]), | |
processData: false, | |
contentType: false | |
}).done(function(res) { | |
}).fail(function(res) {}); | |
//非form方式 | |
<div id="uploadForm"> | |
<input id="file" type="file"/> | |
<button id="upload" type="button">upload</button> | |
</div> | |
var formData = new FormData(); | |
formData.append('file', $('#file')[0].files[0]); | |
$.ajax({ | |
url: '/upload', | |
type: 'POST', | |
cache: false, | |
data: formData, | |
processData: false, | |
contentType: false | |
}).done(function(res) { | |
}).fail(function(res) {}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment