开发者

Parent to sub-domain AJAX POST requests with JQuery

I'll start by saying i have spent the last 3 days looking for an answer to this and have yet to find a solution that works! :(

I would like to be able to POST from www.example.com to api.example.com preferably using JQuery.

I have managed to get GET requests to work using document.domain and <base href="example.com"/>

This is all secured using SSL.

I ha开发者_运维百科ve read about using an iFrame to load a page on the subdomain and post the forms from the parent domain using javascript but i don't really want to pursue this route (if possible).

Also if cross-domain POSTing isn't viable, when using https are there any security benefits with using POST as compared to GET?

Thanks,

Jamie


If you set the document domain in the main domain and the subdomain, you should be able to make Ajax calls between the two.

Parent Page

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

iframe setDocumentDomain.html code

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜