Skip to content

Instantly share code, notes, and snippets.

@wescleymatos
Last active April 19, 2017 14:28
Show Gist options
  • Save wescleymatos/2a5fed6df64b124fe5444944b9098e63 to your computer and use it in GitHub Desktop.
Save wescleymatos/2a5fed6df64b124fe5444944b9098e63 to your computer and use it in GitHub Desktop.
Send ajax jquery with some content-type
// multpart/data
$('form').on('submit', function (e) {
e.preventDefault();
var form = new FormData($(this)[0]);
$.ajax({
method: "POST",
url: URL,
data: form,
processData: false,
contentType: false,
dataType: 'json|html|text'
});
});
// application/x-www-form-urlencoded
$('form').on('submit', function (e) {
e.preventDefault();
var form = $(this);
$.ajax({
method: "POST",
url: URL,
data: form.serialize(),
contentType: "application/x-www-form-urlencoded; charset=utf-8",
dataType: 'json|html|text'
});
});
// application/json
$('form').on('submit', function (e) {
e.preventDefault();
var data = {nome: '', email: ''};
$.ajax({
method: "POST",
url: URL,
data: {data : data},
contentType: "application/json; charset=utf-8",
dataType: 'json|html|text'
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment