非常不多说,直接给大家上干货,写的不好还请见谅。
具体代码如下所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
<!DOCTYPE html> <html> <head> <meta name= "viewport" content= "width=device-width" /> <script src= "~/Scripts/jquery-1.8.2.min.js" ></script> <title>Index</title> <script> $( function () { $( ':button' ).click( function () { var formData = new FormData(); var file = $( "input[type='file']" )[0].files[0]; formData.append( "files" , file); $.ajax({ url: '/Upload/Upload' , //server script to process data type: 'POST' , //Ajax事件 //beforeSend: beforeSendHandler, //success: completeHandler, //error: errorHandler, // Form数据 data: formData, //Options to tell JQuery not to process data or worry about content-type cache: false , contentType: false , processData: false }); }); }); </script> </head> <body> <form enctype= "multipart/form-data" > <input name= "file" type= "file" multiple= "multiple" /> <input type= "button" value= "Upload" /> <input type= "text" name= "userName" value= "ice" /> </form> </body> </html> |
以上代码是小编给大家分享的Ajax异步上传文件实例代码,希望对大家有所帮助,如果大家有疑问欢迎给我留言,小编会及时回复大家的,在此也非常感谢大家对服务器之家网站的支持!