ajax调用接口

今天遇到了一些问题,其中有一个是,当A用ajax调用B的接口时,不能返回数据,后来知道了是因为跨域的问题

public function __construct()
{
    parent::__construct();
    header("Access-Control-Allow-Origin: *");
    header("Access-Control-Allow-Methods:POST,GET");
    header("Access-Control-Allow-Headers:x-requested-with,content-type");
    header("Content-type:text/json;charset=utf-8");
}

在Common控制器里添加上面的,就可以了。

猜你喜欢

转载自blog.csdn.net/ltjy_admin/article/details/83150809