I have wp plugin that when it reutrns the ajax data of woocommerce billing fields in the php function it printed in the console browser, in the index.php
file of the plugin
So I want to be able to get the data normally but for some reason I can't however I have another ajax call on the same localhost runs normally.
function addEvtListenerToCheckoutPage2()
{
?>
<script type="text/javascript">
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
document.addEventListener("DOMContentLoaded", (event) => {
document.getElementById('billing_first_name').addEventListener("focusout", function() {
alert("Hello World!addEvtListenerToCheckoutPage2");
if (document.getElementById('billing_first_name') !== "") {
var billing_first_name = document.getElementById("billing_first_name").value;
my_data = {
action: 'shipping',
billing_first_name_post: document.getElementById("billing_first_name").value
};
jQuery.ajax({
type: "get",
url: "<?php echo admin_url('admin-ajax.php'); ?>",
data: my_data,
success: function(msg) {
console.log("sucess ajax");
console.log(msg);
},
fail: function(msg) {
console.log("error ajax");
}
});
}
});
});
</script>
<?php
}
// can't use any action instead of init but it's fine for now
add_action('init', 'addEvtListenerToCheckoutPage2');
in the rest of the same file
function shipping1()
{
$testing = $_GET['billing_first_name_post'];
echo $testing;
wp_send_json_success();
// this printed in the console not on the server or I mean doesn't process on the back-end
// this's the result which again in the consle : Steve{"success":true}
test_function(); // this's another php function which also when I run it prints in the console
}
add_action('wp_ajax_nopriv_shipping', 'shipping1');
add_action('shipping', 'shipping1');
My Answer:
you please provide more context or clarify your question?
Rate this post
5 of 5 based on 4064 votesComments