How do you get content from another domain with .load()?

后端 未结 4 1810
无人及你
无人及你 2020-12-08 12:46

Requesting data from any location on my domain with .load() (or any jQuery ajax functions) works just fine.

Trying to access a URL in a different domain doesn\'t wor

4条回答
  •  无人及你
    2020-12-08 12:52

    This is because of the cross-domain policy, which, in sort, means that using a client-side script (a.k.a. javascript...) you cannot request data from another domain. Lucky for us, this restriction does not exist in most server-side scripts.

    So...

    Javascript:

    $("#google-html").load("google-html.php");
    

    PHP in "google-html.php":

    echo file_get_contents("http://www.google.com/");
    

    would work.

提交回复
热议问题