I’m using ajax to collect data from enquiry form, then data is send to another page, and this page supposed to send this data to my email.
The problem is when I click send button, I’m getting 404 error in firebug console.
In template (with ajax code) I use this call:
$.ajax({
type: "POST",
url: "<?php echo get_permalink(11); ?>",
data: {
name: $('.enquiryName').val(),
email: $('.enquiryEmail').val(),
comments: $('.enquiryComments').val()
}
}).done(function(msg) {
if (msg=='1') {
alert('<strong>Your enquiry has been sent successfully.</strong>');
$('.enquiryName').val('');
$('.enquiryEmail').val('');
$('.enquiryComments').val('');
} else {
$('.errorBox').html(msg);
}
});
Target page is just another page created in wordpress, with very basic template. When I put to browser url bar this page address and press enter I get message Nothing to send., which is correct.
What might be wrong? In ajax I get 404 error, in browser it’s fine.
You will need to get an instance of the Ajax URL in frontend.
To do that you need to enqueue your script and use the
WP
functionwp_localize_script
so in your
functions.php
and in your JS file you can use the object:
url: ajax_object.ajax_url,
You need to use a relative URL in an Ajax call… replace
<?php echo get_permalink(11); ?>
with the actual relative URL and see if it works..also you must pass an ‘action’ param in your data which can then be attached to callback function
must see this :
http://codex.wordpress.org/AJAX_in_Plugins