Access control for cross site requests in Internet Explorer

后端 未结 6 2384
谎友^
谎友^ 2020-12-28 21:20

I am trying to make an AJAX call from several domains to a single one which will handle the request. Enabling Cross domain in Firefox and Chrome was easy by setting the head

6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-28 22:16

    I don't believe you can do that directly in Internet Explorer. You have a couple of options:

    • Set up a proxy forwarding script on the server you do control that can forward the Ajax requests. Make sure that it only forwards to the appropriate destinations that you need so that you don't get turned into an anonymous relay.

    • Use the document.domain trick. Basically you need to create a set of iframes, one for each server you need to make Ajax calls to. Within each iframe set the document.domain property to exactly match the domain you need to send the Ajax requests to. As to how to populate the necessary data, use DOM manipulation prior to setting document.domain. Note that this trick requires the target servers to be in sub-domains of the original. More in this article, with examples.

提交回复
热议问题