IE中的后台HTTP [英] HTTP in the background in IE

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

问题描述

我需要解决IE限制问题,关于在后台获取HTTP

文档。需要一些解释;请

请耐心等待...


我正在研究一个将在内联网上运行的项目。我需要

当他们反映的数据在服务器上更改为
时,会自动重新加载页面。对于Netscape / Mozilla / Firefox,我这样做是通过

让页面使用JavaScript来读取一个特殊的/update.html。 URL

在后台。对于此URL,服务器在检测到数据发生变化之前不会返回任何内容

,此时它会发送一个

毫无意义的响应并关闭连接。浏览器的

JavaScript代码然后重新加载主页面,显示新数据。

它很棒!


但是还有这个其他浏览器,Internet Explorer,我必须支持b $ b。 慢/ update.html"策略*似乎*工作直到

退出&多次重新加载主页面,没有任何更改
在数据中检测到
。如果我这样做,那么浏览器就会卡住。


当你退出

启动它的页面时,显然IE不会终止背景JavaScript。对于我的应用,这意味着IE尝试

来累积额外的背景" /update.html"每次请求

退出&重新加载主页面。此外,IE似乎只允许总共有6个TCP连接,所以一旦它累积了6

" /update.html"请求,它不能读取任何其他内容。


我得到了背景" /update.html"在IE中工作的策略,通过让它记住哪个线程用于服务

slow" /update.html"请求每个客户,然后当一个新的线程

想要提供新的/update.html时;对于同一个客户端,它首先

杀死旧线程并关闭旧连接。我认为这是一个令人讨厌的hack,但它确实有效。


除了现在我想允许每个客户端执行两个/update.html" <并行请求
请求 - 一个用于主窗口,一个用于弹出窗口

窗口。 (/update.html请求接受描述什么的参数,

,客户想要等待。主窗口和弹出窗口

将等待不同的事情。)我尝试扩展相同的杀死

旧线程破解处理两个连接,但似乎没有工作的b $ b。我可能还没把它上班,但是在我浪费了很多时间之前,我想我会问其他人是否可以提出更好的建议




要重新输入:我想允许每个客户端有两个窗口,当服务器的数据发生变化时,立即重新加载页面。
>

IE的JavaScript环境是否有一些选项用于表示

当页面被卸载时,后台任务是否会死亡?


有没有办法在文件卸载事件中杀死它们,或者某些类似的事件?


提前感谢任何建议你可以给予。

I need a work-around for an IE limitation, regarding fetching HTTP
documents in the background. It takes a bit of explaining; please
be patient...

I''m working on an project that will run on an intranet. I need to
have pages be reloaded automatically when the data they reflect is
changed at the server. For Netscape/Mozilla/Firefox, I do this by
having the page use JavaScript to read a special "/update.html" URL
in the background. For this URL, the server doesn''t return anything
until it detects a change in the data, at which point it sends a
meaningless response and closes the connection. The browser''s
JavaScript code then reloads the main page, showing the new data.
It works great!

But there''s this other browser, "Internet Explorer", which I must
also support. The "slow /update.html" strategy *seems* to work until
I exit & reload the main page multiple times, without any changes
being detected in the data. If I do that, then the browser gets stuck.

Apparently IE doesn''t terminate backgrounded JavaScript when you exit
the page that started it. For my applicatation, this means IE tries
to accumulate extra backgrounded "/update.html" requests each time
you exit & reload the main page. Also, it seems that IE only allows
about 6 TCP connection in total, so once it''s accumulated 6
"/update.html" requests, it can''t read anything else.

I got the background "/update.html" strategy to work in IE, more or
less, by making it remember which thread is being used to serve the
slow "/update.html" request for each client, and then when a new thread
wants to do serve a new "/update.html" for the same client, it first
kills the old thread and closes the old connection. I consider this
a nasty hack, but it works.

Except that now I want to allow each client to perform two "/update.html"
requests in parallel -- one for the main window, and one for a pop-up
window. (The /update.html request accepts parameters describing what,
exactly, the client wants to wait for. The main window and pop-up window
will wait for different things.) I tried extending the same "kill the
old thread" hack to handle two connections, but it doesn''t seem to be
working. I may yet get it to work, but before I waste a lot of time
on it, I thought I''d ask whether anybody else can suggest something
better.

To reitterate: I want to allow each client to have two windows that
immediately reload their pages when the server''s data changes.

Is there some option that IE''s JavaScript environment uses to indicate
whether backgrounded tasks should die when the page is unloaded?

Is there a way to kill them on a document unload event, or some
similar event?

Thanks in advance for any advice you can give.

推荐答案

Steve Kirkendall写道:
Steve Kirkendall wrote:
我正在研究一个将运行的项目在内联网上。当他们反映的数据在服务器上发生变化时,我需要自动重新加载页面。对于Netscape / Mozilla / Firefox,我这样做是为了让页面使用JavaScript来阅读特殊的/update.html。 URL
在后台。对于此URL,服务器在检测到数据发生变化之前不会返回任何内容,此时它会发送无意义的响应并关闭连接。
I''m working on an project that will run on an intranet. I need to
have pages be reloaded automatically when the data they reflect is
changed at the server. For Netscape/Mozilla/Firefox, I do this by
having the page use JavaScript to read a special "/update.html" URL
in the background. For this URL, the server doesn''t return anything
until it detects a change in the data, at which point it sends a
meaningless response and closes the connection.



^^^^^^^^^^^^^^^^^^^^

你要么使用缓存控制头,这会导致响应

如果数据未更改,则使用HTTP状态代码304(未修改),

或者您应该回复_properly_并使用204(无内容)

检测不到数据服务器端的变化。这可能会修复你的IE

问题。


另请注意,您的检查应该以合理的延迟完成,因此请使用

setTimeout / setInterval(),超时/间隔长度大于50

(ms;大概5000 [5 s]是一个不错的值),并且不要在紧张的情况下运行它>
循环。

HTH


PointedEars


^^^^^^^^^^^^^^^^^^^^
Either you use cache control headers which would result in responding
with HTTP status code 304 (Not Modified) if the data was not changed,
or you should respond _properly_ with 204 (No Content) in the case you
detect no change of data server-side. This will probably fix your IE
problem as well.

Also note that your checks should be done with reasonable delay, so use
setTimeout/setInterval() with a timeout/interval length greater than 50
(ms; probably 5000 [5 s] is a nice value), and do not run it in a tight
loop.
HTH

PointedEars


Thomas''PointedEars'' Lahn写道:
Thomas ''PointedEars'' Lahn wrote:
Steve Kirkendall写道:
Steve Kirkendall wrote:
我正在研究一个将在内联网上运行的项目。当他们反映的数据在服务器上发生变化时,我需要自动重新加载页面。对于Netscape / Mozilla / Firefox,我这样做是为了让页面使用JavaScript来阅读特殊的/update.html。 URL
在后台。对于此URL,服务器在检测到数据发生变化之前不会返回任何内容,此时它会发送无意义的响应并关闭连接。
I''m working on an project that will run on an intranet. I need to
have pages be reloaded automatically when the data they reflect is
changed at the server. For Netscape/Mozilla/Firefox, I do this by
having the page use JavaScript to read a special "/update.html" URL
in the background. For this URL, the server doesn''t return anything
until it detects a change in the data, at which point it sends a
meaningless response and closes the connection.


^^^^^^^^^^^^^^^^^^^^
要么使用缓存控制标头,如果使用HTTP状态码304(未修改),将导致响应
如果您没有检测到数据服务器端的更改,则数据未更改,或者您应该使用204(无内容)响应_properly_。这也可能会解决您的IE
问题。

另请注意,您的检查应该以合理的延迟完成,因此使用带有超时/间隔的setTimeout / setInterval()长度大于50
(ms;可能5000 [5 s]是一个不错的值),并且不要在紧密的循环中运行它。


^^^^^^^^^^^^^^^^^^^^
Either you use cache control headers which would result in responding
with HTTP status code 304 (Not Modified) if the data was not changed,
or you should respond _properly_ with 204 (No Content) in the case you
detect no change of data server-side. This will probably fix your IE
problem as well.

Also note that your checks should be done with reasonable delay, so use
setTimeout/setInterval() with a timeout/interval length greater than 50
(ms; probably 5000 [5 s] is a nice value), and do not run it in a tight
loop.




没有涉及循环。也许我在描述我的

申请时太模糊了。


这是一个调度系统。用户大部分时间都在/sasked.html页面上查看

。该页面包含JavaScript,其中
发送一个/update.html请求。当该请求完成时

(可能是几分钟后),浏览器会重新加载/sasked.html页面上的
。 /update.html请求加载在

背景中,因此它不会干扰用户查看和/ b $ b与/ sasked交互的能力。 HTML页面。

/sasked.html中的JavaScript代码如下所示...


var mygetsig = XmlHttp.create();

mygetsig.open(" GET",

" /update.html?timeout = 600& before = today& after = today& p oolid = 1",true);

mygetsig.onreadystatechange = function()

{

if(mygetsig.readyState == 4)

{

if(mygetsig.responseText!="")

{

location.reload();

}

}

}

mygetsig.send(null);


....其中XmlHttp是一个包装器来隐藏XmlHttpRequest / ActiveX

不兼容。


当我说/update.html发送一个无意义的响应时,我的意思是

发送回正常的HTTP 200响应,其中包含格式良好的HTML

文档,其中包含列出所有更改的表格...浏览器

忽略,因为* any * change告诉它重新加载/sasked.html从头开始。



There is no looping involved. Maybe I was too vague in describing my
application.

It''s a scheduling system. The users spend most of their time looking
at a page called /sasked.html. That page contains JavaScript which
sends a single /update.html request. When that request is complete
(which is likely to be several minutes later), the browser reloads
the /sasked.html page. The /update.html request is loaded in the
background so it won''t interfere with the user''s ability to view and
interact with the /sasked.html page. The JavaScript code in
/sasked.html looks like this...

var mygetsig = XmlHttp.create();
mygetsig.open("GET",
"/update.html?timeout=600&before=today&after=today&p oolid=1", true);
mygetsig.onreadystatechange = function()
{
if (mygetsig.readyState == 4)
{
if (mygetsig.responseText != "")
{
location.reload();
}
}
}
mygetsig.send(null);

.... where XmlHttp is a wrapper to hide the XmlHttpRequest/ActiveX
incompatibility.

When I said /update.html sends a "meaningless response", I meant that it
sends back a normal HTTP 200 response containing a nicely formatted HTML
document, with a table listing all of the changes... which the browser
ignores since *any* change tells it to reload /sasked.html from scratch.


Steve Kirkendall写道:
Steve Kirkendall wrote:
我需要一个解决IE限制的方法,关于获取HTTP
文件的背景。需要一些解释;请耐心等待......

我正在研究一个将在内联网上运行的项目。当他们反映的数据在服务器上发生变化时,我需要自动重新加载页面。对于Netscape / Mozilla / Firefox,我这样做是为了让页面使用JavaScript来阅读特殊的/update.html。 URL
在后台。对于此URL,服务器在检测到数据发生更改之前不会返回任何内容,此时它会发送无意义的响应并关闭连接。浏览器的JavaScript代码然后重新加载主页面,显示新数据。
它工作得很好!


如何重新加载页面,例如window.location.reload(true)或

其他一些方法?


但还有其他浏览器,Internet Explorer,我必须
也支持。 慢/ update.html"策略*似乎*工作直到
我退出&多次重新加载主页面,而不会在数据中检测到任何变化。如果我这样做,那么浏览器就会卡住。


"退出&重装" - 退出什么,IE?或者你只是在其他地方导航然后

回到页面?或者你的意思是关闭弹出窗口然后再打开它?


IE有一些已知的内存问题,特别是在关闭方面。如果

你显示你如何调用向服务器发送定期请求

的函数,可能会提供更多帮助。


当您退出启动它的页面时,显然IE不会终止后台运行的JavaScript。对于我的应用,这意味着IE尝试
累积额外的背景" /update.html"每次请求退出&重新加载主页面。此外,似乎IE总共只允许大约6个TCP连接,所以一旦它累积了6
< update.html"请求,它不能读取任何其他内容。


这可能表示cloures有问题,但没有看到代码,

这是不可能的。猜测是可能的,但可能没有帮助。

[...]

IE的JavaScript环境是否有一些选项用于表明
是否有后台任务页面卸载时会死吗?


您是否尝试使用XMLHttpRequest和脚本来更新页面,

而不是使用重新加载?它可能更快,用户不会被重新加载所困扰(闪烁,摧毁正在进行的任何更新,

等)。你可能不得不做更多的会话管理,因为用户

可能正在更新条目,当你从

后面更新它时...


有没有办法在文件卸载事件或类似事件中杀死它们?
I need a work-around for an IE limitation, regarding fetching HTTP
documents in the background. It takes a bit of explaining; please
be patient...

I''m working on an project that will run on an intranet. I need to
have pages be reloaded automatically when the data they reflect is
changed at the server. For Netscape/Mozilla/Firefox, I do this by
having the page use JavaScript to read a special "/update.html" URL
in the background. For this URL, the server doesn''t return anything
until it detects a change in the data, at which point it sends a
meaningless response and closes the connection. The browser''s
JavaScript code then reloads the main page, showing the new data.
It works great!
How are you reloading the page, e.g. window.location.reload(true) or
some other method?

But there''s this other browser, "Internet Explorer", which I must
also support. The "slow /update.html" strategy *seems* to work until
I exit & reload the main page multiple times, without any changes
being detected in the data. If I do that, then the browser gets stuck.
"Exit & reload" - exit what, IE? Or do you just navigate elsewhere then
come back to the page? Or do you mean close the popup then open it again?

IE has some known memory issues, particularly in regard to closures. If
you show how you are calling the function that sends periodic requests
to the server, more help may be available.

Apparently IE doesn''t terminate backgrounded JavaScript when you exit
the page that started it. For my applicatation, this means IE tries
to accumulate extra backgrounded "/update.html" requests each time
you exit & reload the main page. Also, it seems that IE only allows
about 6 TCP connection in total, so once it''s accumulated 6
"/update.html" requests, it can''t read anything else.
This may indicate a problem with cloures, but without seeing the code,
it''s impossible to say. Guesses are possible but likely not helpful.
[...]
Is there some option that IE''s JavaScript environment uses to indicate
whether backgrounded tasks should die when the page is unloaded?
Have you tried using XMLHttpRequest and script to update the page,
rather than using a reload? It is likely faster and the user won''t be
bothered by the re-loads (flashing, trashing any updates in progress,
etc.). You may have to do more session management though, as a user
might be in the middle of updating an entry when you update it from
behind...

Is there a way to kill them on a document unload event, or some
similar event?




尝试Richard Cornford ''终结者:


< URL:http://www.litotes.demon.co.uk/example_scripts/finalizer.html>


Finalizer是一个通用函数,用于安排在

浏览器中的onunload事件期间执行作为参数传递给它的函数
。它的主要目的是解决IE浏览器上的内存泄漏问题,但是已经编写了提供跨浏览器的设施,因为它可能有其他应用程序。< br $> b $ b -

Rob



Try Richard Cornford''s Finalizer:

<URL:http://www.litotes.demon.co.uk/example_scripts/finalizer.html>

"Finalizer is a general function designed to arrange that a function
passed to it as an argument is executed during the onunload event in a
browser. Its primary purpose is to address the memory leak problem on IE
browsers but has been written to provide the facility cross-browser as
it may have other applications."
--
Rob


这篇关于IE中的后台HTTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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