通过axios ajax post将数据传递给php脚本

时间:2018-04-23 04:11:22

标签: php axios

我试图通过axios将数据传递给php脚本,但我没有任何成功 我的脚本如下:

AXIOS SCRIPT

var config = {
   headers: {
     'X-Requested-With': 'XMLHttpRequest',
  }

};

new Vue({
el:'#app',
data:{
    email:'',
    access:''
},
methods:{
    signin:function(){
        console.log(this.email + ' ' + this.access);
        let url = '../App/testConnection.php';
        axios.post(url,{email:this.email, code:this.access}, config)
      .then((response) =>{
          console.log(response.data);
      })
        .catch(function (error) {
            console.log(error);
        });
        //console.log(this.email + ' ' + this.access);
        //alert(this.email);
    }

} });

PHP SCRIPT

        $data = $_POST;
        var_dump($data);

1 个答案:

答案 0 :(得分:0)

您的网址不正确。尝试另一个网址

let url = 'domainname.com/App/testConnection.php';

let url = 'localhost/App/testConnection.php';

如果你测试localy