您的位置:首页 > Web前端 > JQuery

JQuery中ajax跨域问题

2015-01-21 14:54 218 查看
var url = "http://apis.juhe.cn/idcard/index?key=e0a6277420506b2816b82f7d7821976c&cardno="+$(this).val();
$.ajax(url, {
dataType: "json",
crossDomain: true,
success: function(data) {
alert(data)
},
error:function(XMLHttpRequest, textStatus, errorThrown){
alert("1-"+XMLHttpRequest.status);
alert("2-"+XMLHttpRequest.readyState);
alert("3-"+textStatus);
}
});


在测试上面代码的时候,老报这个错误: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. 然而网上查了一下这是ajax的跨域问题。找了两小时的bug之后,后面才发现把dataType的属性值改成 jsonp就行了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: