header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept");
header('Access-Control-Allow-Methods: POST,GET');

在router/router.php头上写上上面的header头就可以正常调用了。

解决办法:

给请求头添加 X-Requested-With 这个参数,参数值为 XMLHttpRequest

// 以 axios 为例
 
this.$axios.get('http://yourdomain.com/api/getMenus', 
{
    headers: {'X-Requested-With': 'XMLHttpRequest'}
 
}).then((res)=>{
                
    // console.log(res.data);
                
})

 

相关文章:

  • 2021-06-23
  • 2022-12-23
  • 2021-11-12
  • 2022-12-23
  • 2021-12-29
  • 2021-07-02
  • 2021-07-15
  • 2022-12-23
猜你喜欢
  • 2021-11-20
  • 2022-12-23
  • 2021-11-04
  • 2022-12-23
  • 2021-10-23
  • 2021-08-12
  • 2021-12-12
相关资源
相似解决方案