跨域请求与jQuery [英] Cross-Domain Requests with jQuery
本文介绍了跨域请求与jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于一个项目,我需要得到不同的其他域的网页的源代码code。 我曾尝试以下code:
For a project I need to get the source code of web page of different other domains. I have tried following code:
$('#container').load('http://google.com');
$.ajax({
url: 'http://news.bbc.co.uk',
type: 'GET',
success: function(res) {
var headline = $(res.responseText).find('a.tsh').text();
alert(headline);
}
});
不过,我没有得到任何结果,但只是一个空白警报框。
Still I am not getting any results but just a blank alert box.
推荐答案
找到了一个更该解决方案:
function getData(url){
if(url.match('^http')){
$.get(url,
function(data){
process(data);
}//end function(data)
);//end get
}
}
这是一个真正的pretty的更简单的方式来处理跨域请求。由于一些网站,如www.imdb.com的拒绝YQL请求。
This is really a pretty easier way to handle cross-domain requests. As some of the sites like www.imdb.com rejects YQL requests.
这篇关于跨域请求与jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文