我尝试使用教程中的示例,但响应文本只是空的。如果我尝试使用“警报”,我会得到OK
,但是使用 responseText,弹出窗口只是空的,里面什么都没有。为什么是这样?
function start(){
var xhr = getXMLHttpRequest();
var sVar1 = encodeURIComponent("firstContent");
var sVar2 = encodeURIComponent("SecondContent");
xhr.onreadystatechange = function() {
if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
//alert("OK");
alert(xhr.responseText);
}
};
xhr.open("GET", "handlingData.php?variable1=" + sVar1 + "&variable2= " + sVar2, true);
xhr.send(null);
}
onsubmit 调用函数“start”:
form id="form_userlogin" onsubmit="start()"
和 PHP 页面:
<?php
header("Content-Type: text/plain");
$variable1 = (isset($_GET["variable1"])) ? $_GET["variable1"] : NULL;
$variable2 = (isset($_GET["variable2"])) ? $_GET["variable2"] : NULL;
if ($variable1 && $variable2) {
echo "OK";
} else {
echo "FAIL";
}
?>
我认为按照教程可以,但不是;p 如果您发现有问题,请告诉我?