I'm not sure I understand how ajax works even though I read a lot about it. I want to run the following php if a button is clicked, without loading the page:
unset($checkout_fields['billing']['billing_postcode']);
So I put the following:
jQuery(document).ready(function($) {
$('.keep-buying-wrapper').click(function(){
$.ajax({
url: "url-to-the-script.php",
method: "POST",
data: {'checked': checked},
success: alert('success!'),
});
});
});
And in my php script:
if( $_POST['checked'] == 'checked' ){
unset($checkout_fields['billing']['billing_postcode']);
}
However nothing happen. even though the success alert is popping, POST['checked'] is null.
Is the ajax supposes to trigger the php script?
What if I want to send some variable to functions.php?
data: {'checked': 'checked'}clickevent