将javascript值的内容获取到php变量中?
我有一个客户需要使用只能通过 javascript 提供的特定跟踪。他希望能够捕获在客户端打印的完全相同的信息。
我如何将其添加到现有的 php 脚本中以将数据添加到数据库中?我唯一的想法是直接在主脚本中回显 javascript,但我似乎无法弄清楚如何从 php 回显中获取值。
有什么想法吗?
i have a client who is required to use specific tracking that is only made available through javascript. he wants to be able to capture the exact same information being printed on the client side.
how can i add this into the existing php script to add the data into the database? my only idea was to echo the javascript directly inside the main script, but i can't seem to figure out how to get the values out of the php echo.
any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这实际上是不可能的,您需要执行 AJAX 调用才能获得类似的东西。
我建议直接用 PHP 实现代码,而不是依赖 Javascript 获取数据。
It's not really possible, you'd need to do an AJAX call to get something similar.
I suggest implementing the code in PHP directly rather then reliying on Javascript for data.
您可以使用虚拟图像将其发送到服务器。
file.php 的内容
这不是最好的方法,但它很快并且可以工作。
You can send it to the server using a dummy image.
contents of file.php
It's not the best way, but it's fast and it will work.
这是不可能的,因为客户端脚本不能直接与服务器端脚本交互,因此它需要你在两者之间有一个“传输器”,即阿贾克斯。看看 jQuery AJAX,它小巧、可爱且功能强大。
但假设有一小块信息,并且不是很机密,我可以建议您使用 cookie 来这样做。人们通常不会利用cookie。
在 PHP 文件中
获取信息后,您可以删除该 cookie。
It is not possible, because client-side script can NOT interact directly with server-side script, therefore it requires you to have a "transporter" in the between, which is AJAX. Have a look at jQuery AJAX, it's tiny, sweet and powerful.
But assume there is a small chunk of information, and it's not very confidential, I can suggest you to do this way, using cookies. People don't usually take advantage of cookies.
In PHP file
Once you finish getting the information, you can delete that cookies.