加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xmlhttprequest cannot load No 'Access-Control-Allow-

发布时间:2020-12-16 03:23:54 所属栏目:百科 来源:网络整理
导读:今天使用JQ的AJAX请求数据,出现了下面的错误 $( ".content" ).on( 'click' , '.synData' , function () { var _this=$( this ); var response=_this.prev().val(); var idcard=_this.prev().prev().val(); $.ajax({ type: 'POST' ,url: 'http://v.juhe.cn/w

今天使用JQ的AJAX请求数据,出现了下面的错误

$(".content").on('click','.synData',function() { 
        var _this=$(this);
        var response=_this.prev().val();
        var idcard=_this.prev().prev().val();
        $.ajax({
            type:'POST',url:'http://v.juhe.cn/weather/index',data:{
                appkey:localStorage.appkey,token:"0d10e9d06ad1a7106d28841582d6fe1c",doc:"{}"
            },success:function(response){
                console.log(response);
            },error:function(){
                console.log();
            }
        });
    });
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 400.

这是一个跨域请求数据的Bug,需要加上

dataType: 'jsonp',
 crossDomain: true,

最后得到的代码是

$.ajax({
    type:'POST',data:{
        appkey:localStorage.appkey,doc:"{}"
    },dataType: 'jsonp',crossDomain: true,success:function(response){
        console.log(response);
    },error:function(){
        console.log();
    }
});

我的就解决问题了

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读