使用jQuery的跨域请求 [英] Cross-Domain Requests with jQuery
本文介绍了使用jQuery的跨域请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于一个项目,我需要获取不同其他域的网页的源代码。
我试过下面的代码:
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.
推荐答案
默认情况下,所有浏览器都限制跨域请求,可以使用YQL作为代理来解决这个问题。请参阅这里的指南: http://ajaxian.com/archives/using -yql-as-a-proxy-for-cross-domain-ajax
By default all browsers restrict cross-domain requests, you can get around this by using YQL as a proxy. See a guide here: http://ajaxian.com/archives/using-yql-as-a-proxy-for-cross-domain-ajax
这篇关于使用jQuery的跨域请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文