【问题标题】:Sub-domain REST call work in FF not in IE子域 REST 调用在 FF 中工作而不在 IE 中
【发布时间】:2012-11-29 03:56:15
【问题描述】:

我有一个使用引导程序设计的 HTML 页面,它调用 REST 服务来更新数据库信息。这是javascript:

$.support.cors = true;

$.ajaxSetup ({
  // Disable caching of AJAX responses
  cache: false,
  async: false
});

$("#submitemail").click(function() {

$.getJSON('http://sub.mydomain.com/getinfo/'+ 
                 encodeURIComponent($('#emailaddress').val()), 
                 function(resp) {
                    //do something here
                  }); 
});

在 FF 中工作。

使用 IE - 如果我从桌面打开 html 文件并运行...它将调用 sub.mydomain.com 并获取信息。但是,如果我从 www.mydomain.com 打开站点并调用该方法 - 什么都没有。用 Fiddler 检查 - IE 甚至不发送请求。

【问题讨论】:

  • 存在回调参数时sub.mydomain.com是否返回有效的JSONP
  • 你看看IE控制台有没有错误?

标签: jquery html cross-browser cross-domain getjson


【解决方案1】:

您不能像这样从主域调用子域。这是一个“跨域”请求,请求会中断。它不应该在www.mydomain.com 上工作——即使在 FF 上也是如此。 我不知道它是怎么做的。

无论如何,您的服务器是如何构建的?是sub.mydomain.com文件夹在mydomain.com/内吗?如:

顶级域名:

http_public/mydomain.com/

子域

http_public/mydomain.com/sub_domains/sub.mydomain.com/

?

如果文件结构是这样的,那么你可以允许访问目录并使用

url: '/sub_domains/sub.mydomain.com/getinfo'+whatever

否则,您需要使用JSONP

JSONP or "JSON with padding" is a complement to the base JSON data format. It provides a method to request data from a server in a different domain, something prohibited by typical web browsers because of the Same origin policy.

【讨论】:

  • 我有 nginx 在前面运行,NodeJS+Restify 用于 API。 Nginx 从主要 www.mydomain 站点的文件夹中提供静态 HTML。 REST 调用由 api.mydomain 提供服务。 Nginx 将 api 路由到 NodeJs。在 FF 上它工作正常..但在 IE 上浏览器没有发送任何内容。
  • 另外,我正在使用 JSONP 调用...$.getJSON()。并有 $.support.cors = true;
猜你喜欢
  • 2010-12-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-03
  • 2023-03-15
  • 2014-05-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多