javascript - Pass variable to php script with AJAX -


i'm not sure understand how ajax works though read lot it. want run following php if button clicked, without loading page:

unset($checkout_fields['billing']['billing_postcode']); 

so put 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 php script:

if( $_post['checked'] == 'checked' ){         unset($checkout_fields['billing']['billing_postcode']); } 

however nothing happen. though success alert popping, post['checked'] null.

is ajax supposes trigger php script?
if want send variable functions.php?

the problem need serialize post data first.

html code (the id , name of checkbox "billing_postcode"):

<input type = "checkbox" id = "billing_postcode" name = "billing_postcode"> 

js code

$(document).on('click', '#billing_postcode', function (event) {      var data = $("#billing_postcode").serializearray();     $.ajax({         url: "url-to-the-script.php",         method: "post",         data: data,         success: alert('success!'),     }) }); 

you value in post array on server side , enter code here in php script:

if($_post['billing_postcode'])     unset($checkout_fields['billing']['billing_postcode']); 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -