Firefox 设置启用跨域 Ajax 请求 [英] Firefox setting to enable cross domain Ajax request

查看:35
本文介绍了Firefox 设置启用跨域 Ajax 请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要暂时允许跨域 XMLHttpRequest.更改 Firefox 安全设置似乎是要走的路.但我试过 thisthis 但他们没有工作.有没有人以前能够配置这个?谢谢.

I need to temporally allow cross domain XMLHttpRequest. Changing firefox security setting seems to be the way to go. But I've tried with this and this but they didnt work. Has anyone been able to configure this before? Thanks.

推荐答案

对于现代浏览器,您可以尝试以下方法:

For modern browsers, you may try the following approach:

https://developer.mozilla.org/en/HTTP_access_control

简而言之,您需要将以下内容添加到 SERVER 响应头中(以下内容允许访问 from foo.example):

In short, you need to add the following into the SERVER response header (the following allows access from foo.example):

Access-Control-Allow-Origin: http://foo.example
Access-Control-Allow-Methods: POST, GET, OPTIONS
Access-Control-Allow-Headers: X-PINGOTHER
Access-Control-Max-Age: 1728000

请注意,X-PINGOTHER 是由 JavaScript 插入的自定义标头,应因站点而异.

Note that the X-PINGOTHER is the custom header that is inserted by JavaScript, and should differ from site to site.

如果您希望任何站点在 Ajax 中访问您的服务器,请改用 *.

If you want any site access your server in Ajax, use * instead.

当我在 2009 之前第一次回答这个问题时,我实际上遇到了同样的问题,我使用服务器端配置解决了这个问题.

When I first answered the question by 2009, I actually hit the same problem, and I worked around it using the server side config.

那时 FF 或 Chrome 上还没有插件.

There was no plugin on FF or Chrome by then.

但是,现在我们有使用浏览器端插件的替代方案,请查看tsds

However, now we do have alternatives using the browser side plugin, please check the answer of tsds

这篇关于Firefox 设置启用跨域 Ajax 请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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