ajax跨域请求数据取到但是进error方法怎么整?

浏览器报错Failed to load http://xxx.com: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
但network里面接口数据都已经过来了,然后ajax那边没进success进了error,查了资料说不是同一个域很有可能造成我这样的情况,请问怎么解决呢

$.ajax({
            url: nowInfo.get,
            get: 'get',
            data: token
            dataType:"text",
            success: function (data) {
                console.log(data)
            },
            error: function (data) {
                console.log(data)
            }
        })
阅读 2.8k
2 个回答

解决跨域即可

  1. cors
  2. nginx 代理
  3. jsonp ,也可在 nginx 做 jsonp 的适配
推荐问题