跨域请求错误提示如下图:
解决方法在请求的 PHP 页面添加 header 头:
代码如下:
- public function test()
- {
- // 支持全域名访问, 不安全, 部署后需要固定限制为客户端网址
- header('Access-Control-Allow-Origin:*');
- // 支持的 http 动作
- header('Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE');
- // 响应头 请按照自己需求添加.
- header('Access-Control-Allow-Headers:x-requested-with,content-type');
- $arr = Querys::selects("index_goods");
- echo json_encode($arr);
- }
来源: http://www.bubuko.com/infodetail-2863957.html