Using JQuery to get the HTML from another website: Possible? Legal?

后端 未结 5 1872
猫巷女王i
猫巷女王i 2021-02-04 14:40

I am trying to get HTML code from a webpage that is not in the same domain. The html text is parsed & summarises a recipe(recipe name, main ingredients, no. of steps) found

5条回答
  •  一生所求
    2021-02-04 15:33

    What you are trying to do can't be done using any AJAX library. Browsers' cross-domain policy won't allow you to do this.

    But you can do this with a combination of php (or any other server-side language) and AJAX. Create a php script like this:

    
    

    Let us say the script's name is fetch.php. Now you can throw an AJAX call from your jQuery code to this fetch.php and it will fetch the HTML code for you.

提交回复
热议问题