Skip to content

Instantly share code, notes, and snippets.

@tianyk
Created December 8, 2016 08:36
Show Gist options
  • Save tianyk/1c2fd6b8ce0ee602d6acaadd8801b01a to your computer and use it in GitHub Desktop.
Save tianyk/1c2fd6b8ce0ee602d6acaadd8801b01a to your computer and use it in GitHub Desktop.
<html>
<head>
<title>文件上传</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<form id="uploadForm" enctype="multipart/form-data">
<input id="file" type="file" name="file" />
<button id="upload" type="button">upload</button>
</form>
</body>
<script src="http://cdn.bootcss.com/jquery/2.2.3/jquery.js"></script>
<script>
$(() => {
$('#upload').click(() => {
$.ajax({
url: '/upload',
type: 'POST',
cache: false,
data: new FormData($('#uploadForm')[0]),
processData: false,
contentType: false
})
.done((res) => { })
.fail((res) => { });
});
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment