<script type="text/javascript" src="https://apis.google.com/js/plusone.js"></script>
<script type="text/javascript">
function testme(data){var i = data.href ;alert(i);
document.getElementById("log").innerHTML=data.href;}
</script>
<g:plusone callback="testme" href="http://stackoverflow.com/"></g:plusone> <!-- div for google post-->
<?php
include('config.php'); //config file
echo "<b id=".log."></b>";
$query1=mysql_query("insert into addd values('log')");
?>
这是我的谷歌发布的点击事件代码。我需要的URL使用PHP我可以从javascript函数获取网址。我需要使用php代码将相同的url存储在我的数据库中。
请注意JavaScript代码执行客户端不在服务器。你的PHP将在服务器上执行,因此它不会得到日志的值。所以你需要添加一个Ajax请求回服务器在Mysql中添加数据 – Vishu238
如果你使用的是MySQL数据库,你需要运行它在服务器上。使用Apache?你的服务器端PHP是什么样的? – ShaharZ