Skip to content

Instantly share code, notes, and snippets.

@slav123
Created February 9, 2021 17:19
Show Gist options
  • Save slav123/5a8985cf697446c8106d018c36242d60 to your computer and use it in GitHub Desktop.
Save slav123/5a8985cf697446c8106d018c36242d60 to your computer and use it in GitHub Desktop.
json ajax form
jsonData = $('#formularz').serializeArray().map(function(x){this[x.name] = x.value; return this;}.bind({}))[0]
$.ajax({
type: "POST",
url: "",
data: JSON.stringify(jsonData),
success: function(data){
if (data.error == "") {
$('#formWrapper').html("<p>Dziekujemy za wysłanie wiadomości</p>");
} else {
console.log(data.error);
$('#formWrapper').html("<p>Wysyłanie wiadomości nie powiodło się.</p>");
}
},
dataType: "json",
contentType : "application/json"
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment