asp.net webapi ajax上传文件示例(jquery)
<h2>Upload</h2><input id="myFile" name="myFile" type="file" />@section scripts { <script> $(document).ready(function () { $('#myFile').change(function () { var file = this.files[0]; var formData = new FormData(); formData.append('MyFile', file); $.ajax({ type: 'POST', url: 'api/files', data: formData, contentType: false, processData: false, success: function () { alert('File uploaded successfully!'); }, error: function () { alert('OOOPS something went wrong!'); } }); }); }); </script>}
评论