如何通过ajax从远程URL获取内容?jQuery ajax请求被阻止,因为跨源
jQuery的Ajax请求是块,因为跨来源
控制台登录
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.dailymotion.com/embed/video/x28j5hv . (Reason: CORS header 'Access-Control-Allow-Origin' missing).
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://www.dailymotion.com/embed/video/x28j5hv . (Reason: CORS request failed).
代码
$.ajax({
url: "http://www.dailymotion.com/embed/video/x28j5hv",
type:'GET',
contentType: "html",
crossDomain:true,
success: function(data){
//$('#content').html($(data).html());
var src = $(data).html();
alert(src);
return false;
}
@ D4V1D对不起,我忘了将它加入到我的问题。如何通过Ajax从远程URL获取内容? –
设置'crossDomain:true'不会设置跨域请求。该网站必须启用CORS才能正常工作。 –
@RoyiNamir你能解释一下吗?我是jquery的新手。 –