admin管理员组文章数量:1323715
I'm strugeling with this ptoblem for a while. Need to pass data from JS to PHP on wordpress site. The error:
<script>
function activatePlacesSearch(){
var input = document.getElementById('shipping_user_location');
var autocomplete = new google.maps.places.Autocomplete(input);
var place;
google.maps.event.addListener(autocomplete, 'place_changed', function(){
place = autocomplete.getPlace();
console.log("Latitude: "+place.geometry.location.lat());
console.log("Longitude: "+place.geometry.location.lng());
$.ajax({
url:"https://DOMAIN/wp-content/themes/techmarket-child/functions.php",
method:"post",
data:{place:JSON.stingify(place)},
success: function(res){
console.log(res);
alert('Ok');
},
error: function(error){
console.log(error);
}
})
});
}
</script>
Finally the code in responsible for autofill the address, and it works. But just simply can't send the data. On the other end i have the this code. But the issue probably on the JS lv:
function add_lat_lng_to_customer_meta($fields){
$place = json_decode($_POST['exampleJS']);
echo $place;die;
return $fields;
}
add_filter( 'woocommerce_customer_save_address', 'add_lat_lng_to_customer_meta' );
If any additional data is need just write me.
本文标签: javascriptERROR while passing data from JS to PHP via AJAX
版权声明:本文标题:javascript - ERROR while passing data from JS to PHP via AJAX 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742125061a2421900.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论