Can I make an XMLHttpRequest to another domain?

后端 未结 7 1508
面向向阳花
面向向阳花 2021-02-18 18:29

Is there a way to use XMLHttpRequest in combination with other domains?

I would like to parse some xml from Google without having to use a server so it is minimalistical

相关标签:
7条回答
  • 2021-02-18 18:35

    Nope, not right now. I believe I read that plans/design's are in the works by standards groups for the future, so we can securely do this.

    Cross site scripting vulnerabilities would be rampant other wise.

    JSONP is a possible solution if the other sites API supports.

    0 讨论(0)
  • 2021-02-18 18:36

    That's not possible due to the SOP (Same Origin Policy) that browser have these days to restrict XSS attacks.
    You will have to use a server side script (PHP or something).

    0 讨论(0)
  • 2021-02-18 18:36

    It is possible to make a XHR to another domain with HTML5.You can also make different protocol request with XHR when communicating with HTTP to another web site.

    0 讨论(0)
  • 2021-02-18 18:37

    You cannot do cross domain request,e.g. from example1.com to example2.com through XMLHttpRequest or jQuery(which is a wrapper of XMLHttpRequest) due to security issue in client side(browser). This can be effectively implemented in modern browser supporting HTML5 through CORS(cross origin resource sharing, which cannot be available in every client browser. So, the solution is to insert script tag in example1.com of example2.com, and this solution is known as JSON-P(JSON with padding), the name could be misleading as the data can be in any format served by the server(example2.com). Its implementation code is given in this link http://newtechinfo.net/jsonp-for-cross-domain-ajax/

    0 讨论(0)
  • 2021-02-18 18:40

    HTML5 now supports Cross Origin requests with XmlHttpRequest level 2 take a look at :

    http://www.html5rocks.com/en/tutorials/cors/

    0 讨论(0)
  • 2021-02-18 18:40

    It's a security issue, most (all?) browsers won't let you do that. You can use a hidden IFrame to do your fetching, but it's complex enough that i'd just use a server (or switch to a different language, if i don't have to run in a browser)

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