2
标题对我正在尝试做的事情非常明确。我想在URL中检索变量vavlue,然后将其发送到add.php。使用JavaScript获取url参数并将其发送到php
我不只是把HTML中的PHP代码的原因是一种形式,也送无功到add.php
PHP代码的:
<?php
$id = $_POST["id"];
?>
Javascript语言,blabla.html? ID =测试
<script>
function getResults()
{
var xmlhttp;
if (window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}
else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("here").innerHTML=xmlhttp.responseText;
}
}
var id = getParameterByName("id");
var data = "id="+document.getElementById("id").value;
xmlhttp.open("POST","add.php",true);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.send(data);
}
</script>
<script>
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
</script>
TNX但我想已经,其假设与“合作” – user2495097