Javascript cross domain - “allow” other domains?

后端 未结 3 1345
青春惊慌失措
青春惊慌失措 2020-12-22 12:10

Description of steps

  1. Write \"callback\" function on my custom page in my domain (called \"MyCallbackCallback\", for the sake of argument)
相关标签:
3条回答
  • 2020-12-22 12:34

    It’s not exactly clear from your question, but if you’re trying to use CORS, the server you’re requesting data from should add an Access-Control-Allow-Origin HTTP header, like so:

    Access-Control-Allow-Origin: http://example.org/
    

    Or, if it’s a public resource:

    Access-Control-Allow-Origin: *
    

    Older browsers don’t support CORS. If you need a fully cross-browser-compatible solution, use JSONP.

    0 讨论(0)
  • 2020-12-22 12:42

    Have a look at Cross-Domain AJAX requests:

    • https://developer.mozilla.org/En/HTTP_Access_Control
    • http://msdn.microsoft.com/en-us/library/dd573303%28v=vs.85%29.aspx

    JSONP is the only method compatible with older browsers though.

    0 讨论(0)
  • 2020-12-22 12:48

    If you want cross-domain communication without serverside proxies (perfect for the kind of RPC that you are describing) then take a look at easyXDM.

    You can find multiple demos here.

    0 讨论(0)
提交回复
热议问题