ajax request to different host

后端 未结 4 1776
逝去的感伤
逝去的感伤 2021-01-22 02:03

i have the following javascript in my webpage:

var xhr = new XMLHttpRequest();
xhr.open(\'GET\', \'http://www.google.com\', true);
xhr.onreadystatechange = funct         


        
4条回答
  •  醉酒成梦
    2021-01-22 02:21

    Cross-site scripting is a common way of injecting code into someone else's web page. To limit this, most browsers now stop the client-side developer from creating a JavaScript request (typically through XMLHttpRequest) to web pages located on a different domain to the original page.

    You can get around this simply by creating a dummy script on your domain that forwards the same request to the page you actually want. For example, in your case, you would create a request to http://mydomain.com/google.php (or whatever scripting language you prefer), which would then download the Google page using file_get_contents or similar and simply echo it out.

提交回复
热议问题