如何解决 Ajax 跨域请求不到的问题?
2个回答
展开全部
跨域访问报错:
XMLHttpRequest cannot load http://v.xxx.com. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access. test.html:1
Resource interpreted as Script but transferred with MIME type text/html:
以下是3种方式解决ajax跨域问题:
$(function($){
var url = '
$.ajax(url, {
data: {
'cityname': '襄阳',
'dtype': 'jsonp',
'key': 'xxxx',
'_': new Date().getTime()
},
dataType: 'jsonp',
crossDomain: true,
success: function(data) {
if(data && data.resultcode == '200'){
console.log(data.result.today);
}
}
});
var url2 = '
$.getJSON(url2, {
'cityname': '北京',
'dtype': 'jsonp',
'key': 'xxxx',
'_': new Date().getTime()
}, function(data){
if(data && data.resultcode == '200'){
console.log(data.result.today);
}
});
var url3 = '
$.get(url3, {
'cityname': '澳门',
'dtype': 'jsonp',
'key': 'xxxx',
'_': new Date().getTime()
}, function(data){
if(data && data.resultcode == '200'){
console.log(data.result.today);
}
}, 'json');
});
更多参考我的blog:http://qiaolevip.iteye.com/blog/2117326
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询