[removed] how to fetch the content of a web page

前端 未结 4 1980
傲寒
傲寒 2021-02-06 07:38

In JS is it possible to fetch the content of a web page assigning it to a variable? For example, why the following toy code does not work?

var req = new XMLHttp         


        
4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-06 08:31

    The above does not work, because Ajax requests cannot access files/pages on other domains, due to security concerns. Typically, you can make a script using [Insert Server Side Language here] to download the requested page. Then your javascript can make a request to this page.

    There is also 'JSONP', but this is typically used on sites that provide specific JSONP access, which most random URL's do not.

提交回复
热议问题