iframe 与普通/ajax 获取请求
我有一个页面,它使用类似于以下内容的 iframe 从几个 IBM WebSphere 服务器收集环境状态:
并且它很高兴地打印出“Started”或“Unavailable”等。但是如果我在普通浏览器有时能用有时不能? 其中一些显示登录页面,而另一些则只是返回 HTTP 代码 500。
那么通过 iframe 加载页面与通过浏览器加载页面有什么区别?
我可以告诉你,无论我在哪台机器上执行 iframe 解决方案,它都可以工作,所以我不相信它与打开页面的用户有任何关系。 在你问之前,为什么不保留有效的解决方案,因为与通过 ajax 请求所有内容的页面相比,使用 iframe 打开页面需要很长时间。
更新:使用 jQuery 执行 ajax 调用会为我在普通浏览器中看不到的服务器返回“错误”和“未定义”。
I have a page that gathers environment status from a couple of IBM WebSphere servers using iframes similar to this:
<iframe src="http://server:9060/ibm/console/status?text=true&type=server&node=NODE&name=ServerName_server_NODE"></iframe>
and it happily prints out "Started" or "Unavailable" etc. But if I load the same url in a normal browser sometimes it works, sometimes it does not? Some of them are showing a login page, while others are simply return HTTP code 500.
So whats the difference between loading the page through an iframe vs through a browser?
I can tell you that the iframe solution works no matter which machine I am doing it on, so I do not belive it has anything to do with the user whos opening the page. And before you ask, why not keep the solution that works, well its because it takes a long time to open the page with the iframes vs a page where everything is requested through ajax.
Update: Using jQuery to perform the ajax call returns "error" and "undefined" for the servers that I can't see in a normal browser.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一个区别是 iframe 必须渲染视图,而 XHR 则不需要。
One difference is an iframe has to render the view while XHR would not.
iframe 本质上与使用浏览器打开相同。 在这两种情况下都使用浏览器凭据,因此两者之间没有区别。
其次,在 iframe 中加载某些内容应该花费与通过 XHR 请求相同的时间,因为在这两种情况下,浏览器都会发出 HTTP 请求并等待响应。 尽管我应该补充一点,iframe 需要一些时间才能将内容呈现到页面上。 但是,如果您打算使用 ajax 来显示它,iframe/xhr 解决方案或多或少会是相同的。
An iframe is essentially the same as opening with the browser. In both cases the browsers credentials are used, so there will be no difference between the two.
Secondly, loading something in an iframe should take the same amount of time as requesting it through XHR, since in both cases the browser makes an HTTP request and waits for the response. Although I should add that an iframe will take time to render the content onto the page. However if you plan on displaying it with ajax anyways, an iframe/xhr solution will be more or less the same.
在 ajax 请求的情况下,同源策略(限制跨域调用)就会出现。 所以你不能使用xhr进行跨域调用。 相同的替代方法是将flex swf文件作为activex控件嵌入到您的页面中,并通过javascript进行flex调用,然后flex负责进行跨域调用(如果目标域允许使用crossdomain.xml进行跨域,则flex可以)并再次使用javascript渲染结果。
In case of ajax request same origin policy (which restricts cross domain call) comes into picture. So you can't make cross domain call using xhr. Alternative for same is embed flex swf file in your page as activex control and make flex call through javascript and then flex is responsible to make cross domain call (flex can if targeted domain allows cross domain using crossdomain.xml) and renders result using javascript again.