jquery ajax get responsetext from http url jquery ajax get responsetext from http url jquery jquery

jquery ajax get responsetext from http url


You simply must rewrite it like that:

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


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:

<?php  echo file_get_contents('http://www.google.de');?>

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);


First you have to download a JQuery plugin to allow Cross-domain requests.Download it here: https://github.com/padolsey/jQuery-Plugins/downloads

Import the file called query.xdomainsajax.js into your project and include it with this code:

<script type="text/javascript" src="/path/to/the/file/jquery.xdomainajax.js"></script>

To get the html of an external web page in text form you can write this:

$.ajax({    url: "http://www.website.com",    type: 'GET',    success: function(res) {        var text = res.responseText;        // then you can manipulate your text as you wish    }});