2015-08-28 52 views
0
<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存储在我的数据库中。

+2

请注意JavaScript代码执行客户端不在服务器。你的PHP将在服务器上执行,因此它不会得到日志的值。所以你需要添加一个Ajax请求回服务器在Mysql中添加数据 – Vishu238

+0

如果你使用的是MySQL数据库,你需要运行它在服务器上。使用Apache?你的服务器端PHP是什么样的? – ShaharZ

回答

-1
get the full URL path in JavaScript: 
var newURL = window.location.protocol + "//" + window.location.host + "/" + window.location.pathname; 

If you need to breath up the pathname: 
var pathArray = window.location.pathname.split('/'); 

Then access the different parts by the parts of the array, like 
var secondLevelLocation = pathArray[0]; 
+0

这个不回答如何更新mysql db – ShaharZ

1

保存在MySQL中,你需要做一个AJAX调用

$.ajax({ 
    url: "test.html", 
    context: document.body 
}).done(function() { 
    $(this).addClass("done"); 
}); 

Java脚本是客户端脚本。您需要将数据从客户端传递到服务器端,发布表单或通过ajax请求。

+1

这是客户端代码,现在你需要在服务器端处理mysql查询 – ShaharZ

0

请注意JavaScript代码在客户端不在服务器中执行。您的PHP将被执行在服务器上,因此它不会得到日志的值..

$.ajax({ 
    url: utl-to-save-data, 
    data: {"log":log} 
}).done(function() { 
    //sussess code; 
}); 
相关问题