Skip to content

Instantly share code, notes, and snippets.

@hieunguyendut
Last active December 26, 2017 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hieunguyendut/c19ba634601ceea853d6f3921aa7a5a9 to your computer and use it in GitHub Desktop.
Save hieunguyendut/c19ba634601ceea853d6f3921aa7a5a9 to your computer and use it in GitHub Desktop.
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("#uploadForm").submit(function(event){
// disable the default form submission
event.preventDefault();
//grab all form data
var formData = new FormData($(this)[0]);
console.log(formData);
$.ajax({
url: 'http://localhost:3001/api/updateProfile',
headers: {
"token": "A4umwMzwmBGFjY3srG/NcSpHYMgxApekMj59Y",
"app-key": "CopyXwPp9xazJ0ku5CZnlmgAx2Dld8SHkAeT"
},
type: 'POST',
data: formData,
async: false,
cache: false,
contentType: false,
processData: false,
success: function (data, textStatus, request) {
console.log(data);
console.log(request.getResponseHeader('token'));
}
});
return false;
});
});
</script>
</head>
<body>
<form ref='uploadForm'
id='uploadForm'
encType="multipart/form-data">
Avatar:<br>
<input type="file" name="avatar" /> <br>
Name:<br>
<input type="text" name="name" /> <br>
Address:<br>
<input type="text" name="address" /> <br>
email:<br>
<input type="email" name="email" /> <br>
<input type="submit"></input>
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment