Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我能够从javascript函数中获取url。我需要使用php代码将相同的url存储在我的数据库中。 函数testme(data){var i=data.href;警报(i); document.getElementById(“log”).innerHTML=data.href;}_Javascript_Php - Fatal编程技术网

我能够从javascript函数中获取url。我需要使用php代码将相同的url存储在我的数据库中。 函数testme(data){var i=data.href;警报(i); document.getElementById(“log”).innerHTML=data.href;}

我能够从javascript函数中获取url。我需要使用php代码将相同的url存储在我的数据库中。 函数testme(data){var i=data.href;警报(i); document.getElementById(“log”).innerHTML=data.href;},javascript,php,Javascript,Php,您需要进行ajax调用 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( '/' ); The

您需要进行ajax调用

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];

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

请注意,Javascript代码在客户端而不是服务器中执行。您的php将在服务器中执行,因此它不会获得log的值

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

请注意,Javascript代码在客户端而不是服务器中执行。您的php将在服务器中执行,因此它不会获得log的值。。所以,您需要将ajax请求添加回服务器,以便在mysql中添加数据。如果您使用的是mysql数据库,则需要在服务器上运行它。使用Apache?服务器端php是什么样子的?这是客户端代码,现在需要服务器端处理mysql查询
$.ajax({
  url: "test.html",
  context: document.body
}).done(function() {
  $( this ).addClass( "done" );
});
$.ajax({
  url: utl-to-save-data,
  data: {"log":log}
}).done(function() {
  //sussess code;
});