Ajax问题,不适用于IE [英] Ajax problem, wont work in IE

查看:76
本文介绍了Ajax问题,不适用于IE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码在Firefox / Netscape中运行正常,但在IE中不起作用。

我怀疑问题出在这两个简单函数之一。如果

没有明显错误,请粘贴整个代码。


////////////////// /////////////////////////////////////


功能get_last_updated(){


http.open(''get'',url);

http.onreadystatechange = handleHttpResponse;

http.send(null);


setTimeout(''get_last_updated()'',5000);


} //结束函数


///////////////////////////////

函数handleHttpResponse(){


if(http.readyState == 4){


last_updated = http.responseText;


if(!first_updated){first_updated = last_updated; }


if(last_updated - first_updated> 0)

{window.location = url; }

}

} //结束功能


/////////////// ////////////////////////////////////////

The following code works fine in Firefox/Netscape but wont work in IE.
I suspect the problem is with one of these two simple functions. If
there is no obvious error Ill paste the entire code.

///////////////////////////////////////////////////////

function get_last_updated() {

http.open( ''get'', url );
http.onreadystatechange = handleHttpResponse;
http.send(null);

setTimeout( ''get_last_updated()'', 5000 );

} // end function

///////////////////////////////

function handleHttpResponse() {

if (http.readyState == 4) {

last_updated = http.responseText;

if ( ! first_updated ) { first_updated = last_updated; }

if ( last_updated - first_updated > 0 )
{ window.location = url; }
}
} // end function

///////////////////////////////////////////////////////

推荐答案

sq****@peoriadesignweb.com 写道:
以下代码在Firefox / Netscape中运行正常但在IE中不起作用。
我怀疑问题出在这两个简单函数之一。如果
没有明显错误,请粘贴整个代码。

////////////////////////// /////////////////////////////

函数get_last_updated(){

http.open(''get'',url);
http.onreadystatechange = handleHttpResponse;
http.send(null);
The following code works fine in Firefox/Netscape but wont work in IE.
I suspect the problem is with one of these two simple functions. If
there is no obvious error Ill paste the entire code.

///////////////////////////////////////////////////////

function get_last_updated() {

http.open( ''get'', url );
http.onreadystatechange = handleHttpResponse;
http.send(null);




作为一个猜测,问题在于你在哪里定义了http对象。

它应该看起来像这里的东西:


< URL :http://jibbering.com/2002/4/httprequest.2004.html>

相关部分复制到下面的等效对象是

,称为xmlhttp。

创建对象

在Internet Explorer中,使用新的

ActiveXObject(" Msxml2.XMLHTTP")创建对象或者新的

ActiveXObject(Microsoft.XMLHTTP),具体取决于安装的MSXML版本

。在Mozilla和Safari中(很可能在未来的UA中,

支持它)你使用新的XMLHttpRequest()


这意味着你需要显示不同的脚本到不同的

浏览器,因为其中一个工作,将在另一个浏览器中出错。下面的脚本

就是这样,如果它不受支持,变量设置为

false以允许适当的错误消息和恢复
当对象

不可用时,
降级为更正常的HTTP事务方法。这种降级很重要,即使在IE中,对象通常会被略微提高的安全设置阻止(当然,流行的应用程序通常被开发的漏洞)。在可能的情况下降级,

下面谈到了一些方法,如果你真的不能,我会建议提供一个替代页面。例如GMail已经表示他们将来会提供一个要求不高的版本,

希望没有任何javascript,完全降级。

var xmlhttp = false;

/ * @ cc_on @ * /

/ * @ if(@_jscript_version> = 5)

// JScript为我们提供了条件编译,我们可以用旧的IE版本处理
//。

//并且安全性阻止了对象的创建。

try {

xmlhttp = new ActiveXObject(" Msxml2.XMLHTTP");

} catch(e){

try {

xmlhttp =新ActiveXObject(" Microsoft.XMLHTTP");

} catch(E){

xmlhttp = false;

}

}

@end @ * /

if(!xmlhttp&& typeof XMLHttpRequest!='' undefined''){

xmlhttp = new XMLHttpRequest();

}



-

Rob



As a guess, the problem is with wherever you''ve defined the http object.
It should look something like the stuff here:

<URL:http://jibbering.com/2002/4/httprequest.2004.html>
The relevant part is copied below where it the equivalent object is
called xmlhttp.
Creating the object

In Internet Explorer, you create the object using new
ActiveXObject("Msxml2.XMLHTTP") or new
ActiveXObject("Microsoft.XMLHTTP") depending on the version of MSXML
installed. In Mozilla and Safari (and likely in future UA''s that
support it) you use new XMLHttpRequest()

This means that you need to show different script to different
browsers, as what works in one, will error in another. The script
below does this, and if it''s not supported, the variable is set to
false to allow for appropriate error messages and recovery with
degrading to more normal HTTP transaction methods when the object
isn''t available. This degradation is important, even in IE the objects
can often be blocked by slightly raised security settings (popular due
to the commonly exploited holes of course). Where possible degrade,
some approaches are talked about below, if you really can''t, I''d
recommend providing an alternative page aswell. GMail for example has
said they''ll be providing a less demanding version in the future,
hopefully with no javascript at all, full degradation.
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
// JScript gives us Conditional compilation, we can cope
// with old IE versions.
// and security blocked creation of the objects.
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
@end @*/
if (!xmlhttp && typeof XMLHttpRequest!=''undefined'') {
xmlhttp = new XMLHttpRequest();
}


--
Rob


谢谢,我试过那段代码,但仍然无法在IE中工作。我认为这可能是因为我正在运行IE6.0的旧版本?我会做一个窗口

更新,看看是否修复了它?

Thanks, I tried that code but still not working in IE. I think it may
be because I am running an older version of IE6.0 ? I will do a windows
update to see if that fixes it?


sq **** @ peoriadesignweb.com 在2006年2月2日上午12:50发表以下内容:


请引用什么您正在回复。


如果您想通过groups.google.com发布后续内容,请不要使用

回复。链接在文章的底部。点击显示选项在

文章的顶部,然后点击回复。在

文章标题的底部。
sq****@peoriadesignweb.com said the following on 2/2/2006 12:50 AM:

Please quote what you are replying to.

If you want to post a followup via groups.google.com, don''t use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.
谢谢,我尝试了该代码,但仍然无法在IE中工作。


将网址发布到您在IE中无法使用的示例页面。


我认为这可能是因为我正在运行IE6.0的旧版本?


令人怀疑但可能。

我会做一个Windows更新,看看是否修复了它?
Thanks, I tried that code but still not working in IE.
Post a URL to a sample page that you have made that doesn''t work in IE.

I think it may be because I am running an older version of IE6.0 ?
Doubtful but possible.
I will do a windows update to see if that fixes it?




您应该更新您的窗口和浏览器以确保它们完全被修补但是它不应该与此有任何关系。


-

兰迪

comp.lang.javascript常见问题 - http://jibbering.com/faq &新闻组每周

Javascript最佳实践 - http://www.JavascriptToolbox .com / bestpractices /



You should update your windows and browser to make sure they are fully
patched but it shouldn''t have anything to do with this.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


这篇关于Ajax问题,不适用于IE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆