为什么我的 AJAX 调用在 Google Chrome 中失败?
我很好奇为什么我的 AJAX 调用在 Google Chrome 中失败,但它在 Firefox 中工作得很好。在有人问之前,我不使用 JQuery,因为我需要访问 readyState == 3,而 JQuery 似乎没有。
我的脚本目前看起来像这样(删除了大的不必要的部分):
function fetch()
{
main = new XMLHttpRequest();
main.open("GET", "<?php echo anchor("thescript"); ?>", true);
var lastResponse = '';
var statusString = 'Step 1(of 3), please wait... ';
main.onreadystatechange = function()
{
if( main.readyState == 1 )
{
alert('Fetch!');
$("#ajax-status").html( statusString );
}
// If there's been an update
if( main.readyState == 3 )
{
}
if( main.readyState == 4 )
{
}
};
main.send(null);
}
它在 Firefox 中完美运行,但在 Chrome 中它甚至不会发出任何警报,因此它甚至不会进入就绪状态 1(即当您发送它时)--这看起来很奇怪......
有什么想法吗?
I am curious as to why my AJAX-call is failing in Google Chrome, it works perfectly fine in Firefox. Before anyone asks, no I'm not using JQuery because I need to have access to readyState == 3 which JQuery doesn't seem to have.
My script currently looks like this(with large unneccessary parts stripped out):
function fetch()
{
main = new XMLHttpRequest();
main.open("GET", "<?php echo anchor("thescript"); ?>", true);
var lastResponse = '';
var statusString = 'Step 1(of 3), please wait... ';
main.onreadystatechange = function()
{
if( main.readyState == 1 )
{
alert('Fetch!');
$("#ajax-status").html( statusString );
}
// If there's been an update
if( main.readyState == 3 )
{
}
if( main.readyState == 4 )
{
}
};
main.send(null);
}
It works perfectly in Firefox but in Chrome it doesn't even alert anything so it doesn't even get into readyState 1(which is when you send it) -- that seems rather odd..
Any ideas??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如上所述:
As noted above: