如何用ajax或javascript进行跨域请求?如何用、ajax、javascript

2023-09-10 17:57:53 作者:红薇染露 ゅ

我有一些pre内置脚本,使一些Ajax请求一个网页。而且它的正常工作。但我不能够做出要求,有一些领域。

I have some Pre built script that makes some ajax request to one website. And it's working fine. But I am not able to make request to there some domains.

我的工作过程: -

My working Process:-

1)我有pre建 http://www.Test.com/a脚本.js文件可现在我调用这个js在这一领域的 http://www.test1.com 通过粘贴code到URL和它的正常工作。

1) I have pre built script on http://www.Test.com/a.js now i am calling this js in this domain http://www.test1.com by pasting the code to URL and it's working fine.

2)现在,当我想从这个 http://hello.test1.com/ as.php 但它显示了一些错误。我怎么能做出要求从主域页子域页。

2) Now When I want to call one page from This http://hello.test1.com/as.php but it's showing some errors. How could i make request to subdomain page from main domain page.

请让我知道我怎么能做到这一点。

Please let me know how can i do this.

在此先感谢。

推荐答案

您的各种选项跨域请求是:

Your various options for cross-domain requests are:

在新的跨域资源共享(CORS)的标准,如果浏览器您的用户使用支持和服务器都有相应的支持。注意,很多一般的网络用户仍然不支持它的浏览器。 JSON-P 的(JSON与填充),这基本上是一个动态 - 增加了剧本元素 使用 YQL (雅虎查询语言)作为的跨域代理 The new Cross-Origin Resource Sharing (CORS) standard, if the browsers your users use support it and the server has support for it. Note that a lot of general web users still have browsers that don't support it. JSON-P ("JSON with padding"), which is basically a dynamically-added script element Using YQL (Yahoo Query Language) as a cross-domain proxy