将JS变量传递给PHP变量 [英] Pass a JS variable to a PHP variable

查看:122
本文介绍了将JS变量传递给PHP变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Google地图给出的JavaScript值,我需要将它保存在MySQL数据库中。

I have a JavaScript value given by Google maps and I need to save it in a MySQL database.

实际上我有变量

<script>
...
var lugar = results[0].geometry.location;// this gives me a latitud, longitud value, like: -34.397, 150.644
...
</script>

我需要将该变量传递给PHP变量lugar

And I need to pass that variable to the PHP variable lugar

<?
$lugar= ?????
?>


推荐答案

你可以 POST 通过表单或者在页面转换时将其传递给URL,然后只需使用 $ _ POST $ _GET 接收变量。

You can POST through a form or pass it in the URL if you're doing it on page transition, then just use $_POST or $_GET to receive the variable.

如果您需要无缝完成,那么您可能需要查看使用AJAX。
TIZAG AJAX教程

If you need it done seamlessly then you might want to look at using AJAX. TIZAG AJAX Tutorial

这篇关于将JS变量传递给PHP变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆