Reputation: 1523
So I have made a WordPress plugin and in the admin page I use an ajax call. It works fine on all my testsites and servers, but now I testing it on a bigger site with multiple other plugins installed. I don't know why but if I press the button that calls the ajax request, nothing is happening.
Here is the code for my ajax call:
jQuery.ajax({
url: "../wp-content/plugins/autocommerce/admin/activatePlugin.php?activate=true",
method: "POST",
data: { txtAC : txtAC, txtKey: txtKey }
}).done(function(msg) {
if(msg == "success") {
jQuery("#admin_activate").append('<input type="hidden" name="txtActivated" value="true" />');
jQuery("#admin_activate").submit();
} else if(msg == "failed") {
jQuery("#activateError").html("Gegevens onjuist. Controleer uw gegevens en probeer het opnieuw.");
} else if(msg == "notSet") {
jQuery("#activateError").html("Een of meerdere velden zijn onjuist ingevuld.");
} else {
alert(msg);
jQuery("#activateError").html("Er is een fout opgetreden. Probeer het later opnieuw.");
}
});
There is no error and on the other sites its just working, so I have no idea where to start looking to solve this problem.
I hope anyone could help me out.
Upvotes: 0
Views: 2210
Reputation: 1689
I would recommend using wordpress standard ajax for that instead of making an ajax call to your own php file:
add_action('wp_ajax_yourfunction', 'yourfunction');
add_action('wp_ajax_nopriv_yourfunction', 'yourfunction');
function nsds_change_password() {
//your functional part goes here
}
Anf then in ajax call use admin ajax url which can be output beforehand like this:
<script type='text/javascript'> var ajaxurl = "<?php echo admin_url('admin-ajax.php'); ?>"; </script>
and the use ajaxurl as a variable and set additonal action parameter wich will be your function name.
Upvotes: 1