简体   繁体   English

我可以从javascript函数获取网址。 我需要使用php代码将相同的URL存储在我的数据库中。

[英]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.

相关问题 我无法获得此代码的输出。 似乎在使用onclick时未调用我的函数 - I am not able to get the output for this code. It seems like my functions are not called when onclick is used 我需要多个按钮来执行相同的 function - 在 JavaScript 中连接 URL - I need multiple buttons to conduct the same function - to concatenate a URL in JavaScript 我正在尝试调用 switch_func function。 但不知何故无法得到想要的结果 - I am trying to call the switch_func function. But somehow not able to get the desired result 我想获取此href(此URL),但是我无法使用CasperJS获取它 - I want to get this href (this URL), but I am not able to get it using CasperJS 我目前正在从我的代码中删除 jquery 并且我无法将此 Jquery 转换为 Javascript - I am currently removing jquery from my code and I am not able to convert this Jquery to Javascript 我正在尝试通过php代码更新记录。 但是我的代码有麻烦 - I am trying to update records by php code. but having trouble in my code 我使用javascript提交表单但我无法在php页面中获取值 - I am submitting form using javascript but I am not able to get values in php page 我需要获取用于登录 MS 的 email 登录到我的应用程序代码。 我如何得到它? - I need to get the email used for signing in to the MS sign in to my application code. How do I get it? 我是Java语言的新手,正在从url获取JSON数据,我只能在成功函数中访问数据,我丢失了什么吗? - I'm new to javascript and I'm fetching JSON data from url, I'm only able to access data in success function, Am I missing something? 为什么我无法将查询提取到我的提取网址中? - Why I am not able to fetch query into my fetch url?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM