Home >Web Front-end >JS Tutorial >Ajax asynchronous file upload example code sharing

Ajax asynchronous file upload example code sharing

韦小宝
韦小宝Original
2018-01-09 09:54:041563browse

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() {
$(&#39;:button&#39;).click(function () {
var formData = new FormData();
var file = $("input[type=&#39;file&#39;]")[0].files[0];
formData.append("files", file);
$.ajax({
url: &#39;/Upload/Upload&#39;, //server script to process data
type: &#39;POST&#39;,
//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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn