【问题标题】:AJAX call to internal server works in IE but not in other browsers对内部服务器的 AJAX 调用在 IE 中有效,但在其他浏览器中无效
【发布时间】:2012-02-03 09:54:24
【问题描述】:

我正在调用我们内部服务器上的服务器站点。该域如下所示:

http://server.domain:12345/x.html

现在,使用 IE 可以正常工作,我正在获取数据。 (我的问题是 IE 会在第一次调用后永久缓存网站,但没关系)。

现在,如果我尝试在 Firefox 中执行完全相同的操作,它将无法正常工作,在 Google Chrome 中也是如此。

萤火虫这样说:

Answer-Header

Connection  Keep-Alive
Content-Length  109
Content-Type    text/html; charset=UTF-8
Keep-Alive  timeout=5000
Server  AbWeb Version SRSG 1.34
Set-Cookie  sessionkey=80da7dfe-1c9c-4460-9592-3ce55cecb379

Request-Header

Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Charset  ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Encoding gzip, deflate
Accept-Language de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
Connection  keep-alive
Host    server.domain:12345
Origin  http://otherserver.domain
Referer http://otherserver.domain/test/
User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20100101 Firefox/5.0

Chrome 是这样说的:

X XMLHttpRequest cannot load http://server.domain:12345/x.html. Origin http://otherservere.domain is not allowed by Access-Control-Allow-Origin.
server.domain:12345/x.html

X Failed to load resource

【问题讨论】:

  • 是关于 Javascript 调用还是整个页面?
  • 什么意思?我只是通过 AJAX 调用此页面,这是我得到的错误。

标签: ajax internet-explorer firefox


【解决方案1】:

您似乎执行跨域 JavaScript 调用。目标服务器必须设置Access-Control-Allow-Origin HTTP 标头。在您的情况下,服务器 http://server.domain 必须设置如下标头:

Access-Control-Allow-Origin: http://otherserver.domain

我不知道为什么它适用于 IE,它可能与您的安全域有关,因为您只是在 Intranet 中工作。

看另一个例子:

【讨论】:

    猜你喜欢
    • 2018-11-30
    • 2015-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-08
    • 1970-01-01
    • 2019-07-09
    相关资源
    最近更新 更多