zoukankan      html  css  js  c++  java
  • 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就行了。

  • 相关阅读:
    MySQL(后篇)
    数据库
    Ajax
    JQuery
    BOM & DOM
    CSS
    HTML
    Python之IO多路复用学习
    vue-router小记
    js中运算符的优先级
  • 原文地址:https://www.cnblogs.com/yuanfy008/p/4238879.html
Copyright © 2011-2022 走看看