使用JQuery向子域AJAX POST请求的父级

时间:2011-09-29 12:14:44

标签: javascript jquery ajax xmlhttprequest cross-domain

我首先要说我过去3天都在寻找答案,但尚未找到有效的解决方案! :(

我希望能够从www.example.com发送到api.example.com,最好是使用JQuery。

我已设法使用document.domain<base href="example.com"/>

获取GET请求

这都是使用SSL保护的。

我已经阅读过使用iFrame在子域上加载页面并使用javascript从父域发布表单,但我真的不想追求这条路线(如果可能的话)。

此外,如果跨域POST不可行,使用https时使用POST与GET相比有什么安全性好处吗?

谢谢,

杰米

1 个答案:

答案 0 :(得分:0)

如果在主域和子域中设置文档域,则应该能够在两者之间进行Ajax调用。

父页面

<script type="text/javascript">
    document.domain = "example.com";
</script>
<iframe src="setDocumentDomain.html" style="display:none"></iframe>

iframe setDocumentDomain.html代码

<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript">
            document.domain = "example.com";
        </script>
        <title>Set Domain</title>
    </head>
    <body>
    </body>
</html>
相关问题