Via WordPress, I have built a form with a successful AJAX response. The fields are empty in the database though! I’m guessing it’s because I’m not serializing my values:
// JavaScript Document
jQuery(document).ready(function($){
jQuery('#newFeedbackForm').submit(function(){
var topic = $('#topic').val();
var name = $('#name').val();
var email = $('#email').val();
var no_results_feedback = $('#no_results_feedback').val();
var post_data = {
action: 'addFeedback',
topic: topic,
name: name,
email: email,
no_results_feedback: no_results_feedback
};
$.post(av_feedback_vars.ajaxurl, post_data, function(response){
if(response == 'success'){
$('#feedback').text('Thank you for your comment.');
}else{
alert(av_feedback_vars.error_message);
}
});
return false;
});
});
How would I use serialize in this case? Thanks for helping a noob (first time at ajax here)
As you can see on http://api.jquery.com/jQuery.post/ data doesn’t have to be serialized. jQuery will format it correctly.
Are you sure all the form data is there? You should inspect a working, non-ajax request and see what post data is sent to find out what to send with ajax (and then inspect that request too).
Chrome Dev tools and Firebug are perfect for ‘request inspecting’. Apparently so are IE Dev tools, but I wouldn’t know †