扎拉(Zarah),一些可能对您有帮助的想法:
正如我在评论中所说,尝试改变这一点:
xmlhttp.open("GET","C:/xampp/htdocs/testing.php?pass_back="+"pass_back",true);
对于类似的东西:
xmlhttp.open("GET","testing.php?pass_back="+"pass_back",true);
考虑到这是到您的网络服务器中名为testing.php的文件的有效路由。 open() 方法的 url 参数必须是某个文件的地址server并且您必须使用有效的URL指向该文件。
另一个想法。您可以使用以下方法发送帖子信息:
xmlhttp.open("POST","testing.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("passback=passback");
所以你可以尝试使用 POST 而不是 GET 发送它,看看会发生什么。这可能会给事情带来一些线索。
更多的东西。
由于您的 php 配置,$_REQUEST 可能不包含任何内容,而 $_GET 包含任何内容。这可能是检查 $_GET 而不是 $_REQUEST 的一个很好的理由。但是,如果您确实想使用 $_REQUEST,here您可以找到有关该主题的更多信息。
EDIT
以下代码(基于您的)适用于我(debian APACHE/php 5.4)。我已将所有代码放在同一页面上。我不太喜欢它,但这只是为了指出它有效。 AJAX 部分将数据发送到 main.php,而 main.php 只是将其接收到的数据发回。然后 AJAX 部分只是提醒服务器给出答案。
main.php
<?php
//**********************************************
//IF $_REQUEST CONTAINS pass_back this is an AJAX call, just send back and die.
if (array_key_exists('pass_back',$_REQUEST)) {
echo $_REQUEST["pass_back"];
die();
}
//***********************************************
echo '<html><head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<script>
function clickButton(currentId, nextId) {
//alert(currentId+","+nextId); //check
/*document.getElementById(currentId).style.display = "none";
document.getElementById(nextId).style.display = "block";
document.getElementById(nextId).style.border = "5px solid red";//check*/
//**************************
var xmlhttp;
if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); }
else { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
alert(xmlhttp.responseText);
}
}
xmlhttp.open("GET","testing.php?pass_back=pass_back",true);
xmlhttp.send();
//**************************
}
</script>
</head><body>';
//String of all the div's
$haystack = '<div id="div1" style="width:500px; height:250px; background-color:#fd77ba">Div1</div>
<div id="div2" style="width:500px; height:250px; background-color:#7781fd">Div2</div>
<div id="div3" style="width:500px; height:250px; background-color:#77fd9b">Div3</div>';
//Print all the divs
echo '<form method="post" enctype="multipart/form-data" accept-charset="utf-8">';
echo $haystack;
echo '<button type="button" onClick="clickButton(1,2)" style="font-family:Oxygen,sans-serif; font-style: normal;font-variant: normal;font-weight: normal;font-size: 99%;line-height: normal;font-size-adjust: none;font-stretch: normal; background-color: #494f50; color: #ffffff; padding-top: 5px;padding-right: 10px;padding-bottom: 5px; padding-left: 10px;margin-top: 50px;margin-right: 10px;margin-bottom: 50px;margin-left: 10px; text-decoration:none;">Submit</button>';
echo '</form>';
echo '</body></html>';
?>
祝你好运。