Home > Article > Web Front-end > Ajax asynchronous file upload example code sharing
This article mainly introduces the Ajax asynchronous upload file example code. It is very good and has the value of reference and learning ajax. Friends who are interested in ajax can refer to it
Very few I said, I will provide you with practical information directly. Please forgive me if the writing is not good.
The specific code is as follows:
<!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>
The above code is the Ajax asynchronous file upload example code shared by the editor. I hope it will be useful to everyone. Helps! !
Related recommendations:
Ajax implementation of simulated keyword intelligent matching search effect example tutorial
Ajax cross-domain perfect solution example sharing
Ajax method to implement loading progress bar
The above is the detailed content of Ajax asynchronous file upload example code sharing. For more information, please follow other related articles on the PHP Chinese website!