<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')");
?>
这是我的Google帖子点击事件代码。我需要使用php
将url保存在mysql中答案 0 :(得分:1)
你需要进行ajax调用
$.ajax({
url: "test.html",
context: document.body
}).done(function() {
$( this ).addClass( "done" );
});
java脚本是客户端脚本。您需要将数据从客户端传递到服务器端,无论是发布表单还是通过ajax请求。
答案 1 :(得分:0)
请注意Javascript代码在Client中执行,而不是在服务器中执行。你的php将在服务器中执行,因此它不会获得log的值..
$.ajax({
url: utl-to-save-data,
data: {"log":log}
}).done(function() {
//sussess code;
});
答案 2 :(得分:-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];