JQuery中ajax跨域问题

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就行了。

posted @ 2015-01-21 14:54  玉树临枫  阅读(268)  评论(0编辑  收藏  举报