Greetings, how can I download some page content using ajax and jquery: I am doing something like that (2 versions inside one script):
$("p").click(function() {
$('#result').load('http://google.com');
$.ajax({
url='www.google.com',
success: function(data) {
$("result").html(data);
alert('Load was performed.');
var url = 'www.wp.pl';
$('div#result').load(url);
//var content = $.load(url);
//alert(content);
//$("#result").html("test");
}
});
});
but it does not return any content
Due to restrictions you cannot download the contents of a web page using AJAX that is not hosted on the same domain as the domain hosting this script. Also you have a syntax error in your .ajax
function call. It should look like this:
$.ajax({
url: 'http://yourdomain.com/page1.htm',
success: function(data) {
$("result").html(data);
alert('Load was performed.');
var url = 'http://yourdomain.com/page2.htm';
$('div#result').load(url);
}
});
You could use YQL to proxy your call:
$.ajax({
url:"http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D'http://www.google.com'&format=xml&callback=callback",
type: 'GET',
dataType: 'jsonp'
});
function callback(data){
$('#result').html(data.results[0]);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With