Reputation: 34145
I am making ajax requests in wordpress to admin-ajax.php
file using jQuery:
function ajaxSubmit() {
var FormData = jQuery(this).serialize();
jQuery.ajax({
type: "POST",
url: "/wp-admin/admin-ajax.php",
data: FormData,
success: function(data) {
console.log(data);
}
});
return false;
}
$('#form').submit(ajaxSubmit);
here is the code from functions.php
file:
function activitysubmitTeamMeetingPt(){
die(var_dump($_POST, $_GET));
}
add_action( 'wp_ajax_activitysubmitTeamMeetingPt', 'activitysubmitTeamMeetingPt' );
add_action( 'wp_ajax_nopriv_activitysubmitTeamMeetingPt', 'activitysubmitTeamMeetingPt' );
Also, in the form I do have a hidden attribute for action
<input type="hidden" name="action" value="submitTeamMeetingPt" />
As per the code, all form data would be printed on the screen but that doesn't happen. And I have verifed from firebug that Xhr
request to admin-ajax.php
is being fired but for some reason activitysubmitTeamMeetingPt()
doesn't get called/executed and ajax request just returns 0 with http statuscode 200.
Now,I am wondering was why activitysubmitTeamMeetingPt()
is not being executed?
Upvotes: 1
Views: 720
Reputation: 34145
Update, I figured it out. hidden attribute for action
should be:
<input type="hidden" name="action" value="activitysubmitTeamMeetingPt" />
now it works just fine. thanks for looking everyone
Upvotes: 3