简体   繁体   中英

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. I need the url to be saved in mysql using php

you need to make an ajax call

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

java script is client side script. you need to pass data from client side to server side either posting form or by ajax request.

Please note the Javascript code execute in Client not in server. Your php will get executed in server and hence it will not get the value of 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];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM