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

你可能感兴趣的:(jquery)