AXIOS笔记

2018年4月13日 0 条评论 790 次阅读 0 人点赞

1. axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';

    加上这个header,在method 是POST时,PHP可以使用 $_POST 获取,否则要使用 file_get_contents('php://input')。

2. axios.defaults.withCredentials = true; 

    跨域时,如果要使用Cookie,可以加上 withCredentials= true。

    后端页面,也需要加上相应的 header。

        header('Access-Control-Allow-Origin: http://localhost:8080');

        header('Access-Control-Allow-Credentials: true');

        header("Access-Control-Allow-Methods: POST, GET, OPTIONS, PUT, DELETE");

        header('Access-Control-Allow-Headers:x-requested-with,content-type');

guojia

这个人太懒什么东西都没留下