What prevents me from using $.ajax to load another domain's html?

前端 未结 4 1386
遇见更好的自我
遇见更好的自我 2020-12-17 06:31

My domain:

  


scrape


        
相关标签:
4条回答
  • 2020-12-17 07:04

    It's the Same Origin Policy, which prevents cross-domain requests. If you want to scrape html, you are better off writing a server side process to get the content, then use ajax to make a request against your server, which contains the harvested data.

    0 讨论(0)
  • 2020-12-17 07:09

    the Same Origin Policy prevents client side scripts from getting data from domains that are not from the originator for the request. You would need a server side script to act as a proxy

    0 讨论(0)
  • 2020-12-17 07:12

    There are Four ways to get around Same Origin Policy

    1. Proxy - You request it from your server, your server requests it from other domain, your server returns it to the browser
    2. Flash cross domain policy - other domain must add a crossdomain.xml file to their site
    3. Cross domain HTTP header - other domain must add an Access-Control-Allow-Origin header to their page
    4. JSONP - It's a json web service that provides a callback function. Other domain must implement this.

    Note: The ONLY way to do it without the other domain's help is #1, routing it through your own server.

    0 讨论(0)
  • 2020-12-17 07:19

    One workaround is to make a server-side script (eg. PHP) to get the page, and have $.ajax call that.

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