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