Last active
April 19, 2017 14:28
-
-
Save wescleymatos/2a5fed6df64b124fe5444944b9098e63 to your computer and use it in GitHub Desktop.
Send ajax jquery with some content-type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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