Skip to content

Instantly share code, notes, and snippets.

@adamcrampton
Last active March 13, 2020 05:10
Show Gist options
  • Save adamcrampton/758d02bd0a01d0697aaee63dd013693b to your computer and use it in GitHub Desktop.
Save adamcrampton/758d02bd0a01d0697aaee63dd013693b to your computer and use it in GitHub Desktop.
Boilerplate for jQuery AJAX POST request
const endpoint = 'https://api.some.endpoint.test';
const formId = 'this-form-id-value';
const data = new FormData(document.getElementById('formId'));
$.ajax({
async: true,
contentType: false,
processData: false,
url: endpoint,
method: 'POST',
data: data,
beforeSend: function(jqXHR, settings) {
},
error: function(jqXHR, textStatus, errorThrown) {
},
success: function(data, textStatus, jqXHR) {
},
complete: function(jqXHR, textStatus)
{
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment