thinkphp服务器接受axios请求后,返回成功状态会以html方式,而不是类似ajax的json格式。这是由于axios没有像ajax那样在请求头中默认设置了 {X-Requested-With:'XMLHttpRequest'}
当axios中需要设置请求头时,如果apache服务器端设置了Header set Access-Control-Allow-Headers,需要同时设置允许接收X-Requested-With。
如:
Header set Access-Control-Allow-Origin "http://localhost:8080"
Header set Access-Control-Allow-Headers Origin,Content-Type,Accept,Authorization,X-Requested-With
Header set Access-Control-Allow-Credentials true
Header set Access-Control-Expose-Headers Authorization