jquery ajax get responsetext from http url

后端 未结 9 1348
盖世英雄少女心
盖世英雄少女心 2020-12-07 19:14

Neither:

var response = $.ajax({
    type: \"GET\",   
    url: \"http://www.google.de\",   
    async: false,
    success : function() {
        alert (this         


        
9条回答
  •  被撕碎了的回忆
    2020-12-07 19:48

    Since jQuery AJAX requests fail if they are cross-domain, you can use cURL (in PHP) to set up a proxy server.

    Suppose a PHP file responder.php has these contents:

    $url = "https://www.google.com";
    $ch      = curl_init( $url );
    curl_set_opt($ch, CURLOPT_RETURNTRANSFER, "true")
    $response= curl_exec( $ch );
    curl_close( $ch );
    return $response;
    

    Your AJAX request should be to this responder.php file so that it executes the cross-domain request.

提交回复
热议问题