weixin_33738555 2017-05-01 15:09 采纳率: 0%
浏览 20

空响应文本的ajax

I have a simple ajax query working perfectly in other environment
(complete file named adv1.php):

remark: this is NOT cross-domain, as answered in many questions on this site!

<?PHP
if($_GET['uin']=='1') {
    sleep(10);
    echo 4711;
    exit;
}
?>
<html><head><title>ajax</title></head><body>
<script type='text/javascript'>
ajax=new XMLHttpRequest();
ajax.open('GET', 'adv1.php?uin=1', true);
ajax.send(null);
ajax.onreadystatechange=showres;
alert('request sent');

function showres() {
    if(ajax.readyState==4){
        alert('ajax says: ' + ajax.responseText + 'status:' + ajax.status);
    }
}
</script>
</body></html>

so when I run the code, I expect a waiting time of 10 secs (sleep...) and afterwards the responsetext 4711. what I get instead is: "ajax says: status:0" on the otherf hand, when i enter the url http://path/to/my/file/adv.php?uin=1 I get the correct answer.

i have copied and adapted this script from another script on my site. the other script works perfectly...

the script doesnt throw any console-error...

any help? thx in advance!

  • 写回答

1条回答 默认 最新

  • weixin_33728268 2017-05-03 18:38
    关注

    Move ajax.onreadystatechange = showres; before ajax.send(null);.

    Here are some examples.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题