Loading cross-domain endpoint with AJAX

前端 未结 9 1859
醉酒成梦
醉酒成梦 2020-11-21 05:20

I\'m trying to load a cross-domain HTML page using AJAX but unless the dataType is \"jsonp\" I can\'t get a response. However using jsonp the browser is expecting a script m

9条回答
  •  花落未央
    2020-11-21 05:39

    To get the data form external site by passing using a local proxy as suggested by jherax you can create a php page that fetches the content for you from respective external url and than send a get request to that php page.

    var req = new XMLHttpRequest();
    req.open('GET', 'http://localhost/get_url_content.php',false);
    if(req.status == 200) {
       alert(req.responseText);
    }
    

    as a php proxy you can use https://github.com/cowboy/php-simple-proxy

提交回复
热议问题