jquery ajax get responsetext from http url

stephan picture stephan · Jul 20, 2009 · Viewed 265k times · Source

Neither:

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

Nor:

var response2 = $.get("http://www.google.de", function(data) {
    alert("Data Loaded: " + data);
});

give me an object. How do I get access to the responseText?

Answer

stoimen picture stoimen · Jul 20, 2009

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