Greetings, how can I download some page content using ajax and jquery: I am doing something like that (2 versions inside one script):
问候,如何使用ajax和jquery下载一些页面内容:我正在做类似的事情(一个脚本中有2个版本):
$("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
但它不会返回任何内容
5 个解决方案
#1
7
You could use YQL to proxy your call:
您可以使用YQL代理您的通话:
$.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]);
}
#2
7
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下载网页内容。您的.ajax函数调用中也存在语法错误。它应该如下所示:
$.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);
}
});
#3
2
While it is not possible to directly query a host that is external to the current domain from Javascript, you could use a proxy script to retrieve the desired data.
虽然无法从Javascript直接查询当前域外部的主机,但您可以使用代理脚本来检索所需的数据。
Cross domain AJAX querying with jQuery: http://jquery-howto.blogspot.com/2009/04/cross-domain-ajax-querying-with-jquery.html
使用jQuery查询跨域AJAX:http://jquery-howto.blogspot.com/2009/04/cross-domain-ajax-querying-with-jquery.html
You could also make use of the flXHR script, which can be dropped into many Javascript libraries (including jQuery).
您还可以使用flXHR脚本,该脚本可以放入许多Javascript库(包括jQuery)中。
flXHR: http://flxhr.flensed.com/
flXHR:http://flxhr.flensed.com/
#4
1
You could also simply call a PHP/ASP/RUby page that in turn does the outside calling for you and presents the information in a way that you need.
你也可以简单地调用一个PHP / ASP / RUby页面来反过来为你做外部调用,并以你需要的方式呈现信息。
1. PAGE --> PHP --> External web
(Ajax)
2. PAGE <-- PHP <-- External web
(callback)
#5
1
You need to use something called JSONP to go across domain. Seider has psoted more details on how to do this with jQuery.
您需要使用名为JSONP的内容来跨域。 Seider提供了有关如何使用jQuery执行此操作的更多详细信息。
#1
7
You could use YQL to proxy your call:
您可以使用YQL代理您的通话:
$.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]);
}
#2
7
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下载网页内容。您的.ajax函数调用中也存在语法错误。它应该如下所示:
$.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);
}
});
#3
2
While it is not possible to directly query a host that is external to the current domain from Javascript, you could use a proxy script to retrieve the desired data.
虽然无法从Javascript直接查询当前域外部的主机,但您可以使用代理脚本来检索所需的数据。
Cross domain AJAX querying with jQuery: http://jquery-howto.blogspot.com/2009/04/cross-domain-ajax-querying-with-jquery.html
使用jQuery查询跨域AJAX:http://jquery-howto.blogspot.com/2009/04/cross-domain-ajax-querying-with-jquery.html
You could also make use of the flXHR script, which can be dropped into many Javascript libraries (including jQuery).
您还可以使用flXHR脚本,该脚本可以放入许多Javascript库(包括jQuery)中。
flXHR: http://flxhr.flensed.com/
flXHR:http://flxhr.flensed.com/
#4
1
You could also simply call a PHP/ASP/RUby page that in turn does the outside calling for you and presents the information in a way that you need.
你也可以简单地调用一个PHP / ASP / RUby页面来反过来为你做外部调用,并以你需要的方式呈现信息。
1. PAGE --> PHP --> External web
(Ajax)
2. PAGE <-- PHP <-- External web
(callback)
#5
1
You need to use something called JSONP to go across domain. Seider has psoted more details on how to do this with jQuery.
您需要使用名为JSONP的内容来跨域。 Seider提供了有关如何使用jQuery执行此操作的更多详细信息。