I've using jQuery on my contact form for a web app we're building, I am getting a JSON response from the server which is:
{"success": true}
Here's my jQuery so far:
$('.contact-form').on('submit', function(e) {
// Prevent submitting
e.preventDefault();
// Loading from data-* attr
var $submit = $('#contact-submit');
$submit.html($submit.data('text'));
// Form data
var form = $(this);
var post_url = form.attr('action');
var post_data = form.serialize();
// Ajax call
$.ajax({
type : 'POST',
url : post_url,
data : post_data,
dataType: 'json',
success: function(){
},
error: function(){
}
});
});
I've hit a wall as I've never 'checked' against a JSON response before in the 'success' jQuery method, can anyone help on this? I am looking for a method of checking the response I'm getting, and if 'true' is presented, I will then show a 'Sent success' message.