在网页中,我使用的是XMLHttpRequest。我有麻烦了,因为事情不像平常那样发生了。
以下是相关代码:
let xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// Here useful work is done.
.......
}
}
xmlHttp.open("GET","readUser.php?EL="+user.email,true);
xmlHttp.send();但最近由于某种原因,这种情况正在发生:
this.status == 200 (as expected)但是:
this.readyState == 3 (and not 4 as usual)因此,“有用的工作”没有完成。
我怎样才能让"this.readyState“回到4呢?
或者我怎样才能找到为什么"this.readyState“不是它应该有的4呢?
我使用XMLHttpRequest的经验是相当有限的,所以当事情出了问题时,我会有点不知所措。旁边当我运行"readUser.php?EL=somemail@example.com“(独立)。没有问题,我看不出有什么问题。
我尝试过使用Firefox、Chrome和Safari来实现同样的行为,所以我认为这不是一个与浏览器相关的问题。
++++++供参考,readUser是一个readUser.php页面,下面是readUser.php中的相关代码
<?php
....
ConnectToDB();
$query = 'SELECT * FROM MyDBTable';
$query .= sprintf(" WHERE MlAdr='%s'",$_GET['EL']);
$DBS=$Connection->query($query);
$DBS->setFetchMode(PDO::FETCH_ASSOC);
$dataJSON = json_encode($DBS->fetch());
echo $dataJSON;
?>发布于 2019-08-15 05:49:03
而不是使用xmlHttp.onreadystatechange
xmlHttp.onload = function() {
if (this.status == 200) {
// Here useful work is done.
.......
}
}xhr (XMLHttpRequest)方法是oldscool -考虑使用更现代的方法:获取。
发布于 2019-08-15 05:50:26
检查readUser.php是否完成响应(发送所有数据和关闭连接)。
https://stackoverflow.com/questions/57505295
复制相似问题