jquery ajax get responsetext from http url

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

Neither:

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


        
9条回答
  •  -上瘾入骨i
    2020-12-07 19:42

    As Karim said, cross domain ajax doesn't work unless the server allows for it. In this case Google does not, BUT, there is a simple trick to get around this in many cases. Just have your local server pass the content retrieved through HTTP or HTTPS.

    For example, if you were using PHP, you could:

    Create the file web_root/ajax_responders/google.php with:

    
    

    And then alter your code to connect to that instead of to Google's domain directly in the javascript:

    var response = $.ajax({ type: "GET",   
                            url: "/ajax_responders/google.php",   
                            async: false
                          }).responseText;
    alert(response);
    

提交回复
热议问题