Skip to content

Instantly share code, notes, and snippets.

@netmarkjp
Created August 18, 2015 15:54
Show Gist options
  • Save netmarkjp/e4383567c62859e01d34 to your computer and use it in GitHub Desktop.
Save netmarkjp/e4383567c62859e01d34 to your computer and use it in GitHub Desktop.
ajax post form with jQuery
$("#enqueue_form").submit(function(event) {
event.preventDefault(); //cancel event
var form_data = new FormData($("#enqueue_form").get(0));
$.ajax({
url: "/bench",
type: "POST",
data : form_data,
dataType: "json",
processData: false,
contentType: false,
timeout:10000,
success: function(data) {
// do something
console.log(data);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
// do something
console.log(XMLHttpRequest);
console.log(textStatus);
console.log(errorThrown);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment