var jsonObject = {};
jsonObject['name'] = jQuery('#nameInput').val();
jsonObject['email'] = jQuery('#emailInput').val();
jsonObject['message'] = jQuery('#messageInput').val();
jsonObject['product'] = jQuery('#productOwnedInput').val();
jsonObject['company'] = jQuery('#companyInput').val();
jsonObject['reason'] = jQuery('#reasonInput').val();
jsonObject['contact'] = jQuery('#contactInput').val();
jQuery.ajax({
type: "POST",
url: "<?php bloginfo('template_url'); ?>/sendform.php",
data: JSON.stringify(jsonObject),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
alert('success');
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
From novice to tech pro — start learning today.
Suggest you use alert() to print out the JSON string and copy/paste it here. You may also want to read this article. It's not directly about JavaScript and JSON, but it may give a clue to how UTF-8 collisions can make a mess of otherwise good work.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11880-Unicode-PHP-and-Character-Collisions.html