[英]I am able to get the url from javascript function. I need same url to be stored in my database using php code.
<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')");
?>
This is my code for click event for google post. 这是我的Google Post点击事件代码。 I need the url to be saved in mysql using php
我需要使用php将网址保存在mysql中
you need to make an ajax call 你需要打一个ajax电话
$.ajax({
url: "test.html",
context: document.body
}).done(function() {
$( this ).addClass( "done" );
});
java script is client side script. Java脚本是客户端脚本。 you need to pass data from client side to server side either posting form or by ajax request.
您需要通过发布表单或ajax请求将数据从客户端传递到服务器端。
Please note the Javascript code execute in Client not in server. 请注意,JavaScript代码是在客户端而不是在服务器中执行的。 Your php will get executed in server and hence it will not get the value of log..
您的php将在服务器中执行,因此不会获取log的值。
$.ajax({
url: utl-to-save-data,
data: {"log":log}
}).done(function() {
//sussess code;
});
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];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.