ajax 本地主机::跨域ajax

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3849200/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 10:55:17  来源:igfitidea点击:

localhost :: cross domain ajax

ajaxlocalhost

提问by Hailwood

Is there any way to tell your localhost that it can do cross domain ajax calls?

有什么方法可以告诉您的本地主机它可以进行跨域ajax调用吗?

I need this for my testing.

我需要这个来进行测试。

If it is a browser specific issue i am using google chrome.

如果它是浏览器特定的问题,我正在使用谷歌浏览器。

Cheers.

干杯。

采纳答案by David says reinstate Monica

No, it's absolutely not possible. If it could be disabled by the user then it would be the main target for anyone with nefarious or dubious intent, and as prone as any other software to exploitation. It's difficult enough making secure software, without painting on even more attractive targets.

不,这绝对不可能。如果它可以被用户禁用,那么它将成为任何具有恶意或可疑意图的人的主要目标,并且与任何其他软件一样容易被利用。制作安全软件已经够困难了,而无需绘制更具吸引力的目标。

The only way to implement cross-domain Ajax is to route requests via a server-side script.

实现跨域 Ajax 的唯一方法是通过服务器端脚本路由请求。

It's worth mentioning that there is, perhaps, a glimmer of hope for you: in the form of cross-window messaging with HTML 5 postMessage

值得一提的是,您或许还有一线希望:以 HTML 5 postMessage跨窗口消息传递的形式

It's probably worth your having a read of some related (though I'm not sure they're duplicate) questions:

阅读一些相关(尽管我不确定它们是否重复)的问题可能值得您阅读:



Edited编辑回应评论:

So you mean have a script that takes the params, adds them to the request, sends it out, and then echos out the response object?

所以你的意思是有一个脚本来获取参数,将它们添加到请求中,发送出去,然后回显响应对象?

Essentially yes. In picture format:

基本上是的。图片格式:

client  |--------------> | server side |----------------------->  | remote domain
browser | <----ajax------|   script    | <------------------------|--/


Editedto add that this is now sort of possible, using Cross-Origin Resource Sharing (CORS); in which a script from one domain sends an Origin HTTP header stating the URL of the page, and the server can respond (if configured to do so) with either an error (if CORS is disabled, or unsupported) or with any requested data.

编辑补充说,现在可以使用跨源资源共享(CORS);其中来自一个域的脚本发送一个 Origin HTTP 标头,说明页面的 URL,服务器可以响应(如果配置为这样做)错误(如果 CORS 被禁用或不受支持)或任何请求的数据。

References:

参考:

回答by phillihp

It's very possible. Let's start with a dev browser.

这是很有可能的。让我们从开发浏览器开始。

Step 1:Download Chromium

第 1 步:下载 Chromium

Windows -- http://www.chromium.org/getting-involved/download-chromium

Windows -- http://www.chromium.org/getting-involved/download-chromium

Mac -- http://www.macupdate.com/app/mac/36244/chromium/

Mac—— http://www.macupdate.com/app/mac/36244/chromium/

There should be a build ready to go, but these locations change over time. So if these end up with 404's do a Google search for Windows Chromium Download and you'll find it.

应该有一个准备就绪的构建,但这些位置会随着时间的推移而变化。因此,如果这些以 404 结尾,请在 Google 上搜索 Windows Chromium 下载,您会找到它。

Step 2:Then run the executable with this flag after it. --disable-web-security

第 2 步:然后运行带有此标志的可执行文件。--disable-web-security

Windows -- Create a shortcut to the executable and tag this in the Properties. Or run from [CMD].

Windows -- 创建可执行文件的快捷方式并在属性中标记它。或者从 [CMD] 运行。

Mac -- Open up a terminal and run this straight from there with the flag.

Mac——打开一个终端并直接从那里用标志运行它。

And, you should be good to go. I also setup a quick Apache service and run through a 127.0.0.1 configured domain, but localhost should be just fine. Here's proof.

而且,你应该很高兴去。我还设置了一个快速的 Apache 服务并通过 127.0.0.1 配置的域运行,但 localhost 应该没问题。这是证据。

Cross-domain security block disabled

跨域安全块已禁用

I hope this helps you!

我希望这可以帮助你!