vue-resource和php跨域

来源:互联网 发布:获取windows 7密钥 编辑:程序博客网 时间:2024/06/06 00:15
今天用vue-resource发送ajax,不知道为什么一直失败,刚开始我以为是跨域问题,就在php里加上了
header('Access-Control-Allow-Origin:*');

他的作用是可以让任何域名访问,结果还是获取不到数据。。。。后来发现是因为我的this写错了。同时还要加上emulateJSON属性才可以

            var that=this;            this.$http.post("http://192.168.188.145/CLserver/index.php",{              controller:"reg",              username:that.username,              password:that.password,              email:that.email            },{emulateJSON:true}).then(              function (res) {                if(res.ok){                  mui($event.target).button('reset');                }                console.log(res.data);              },function (res) {                console.log(res);              }            );

再附上angular跨域》》》

angular跨域的时候post请求使用data发送json的时候后台是接收不到数据的。需要转换成a=1&b=2&c=3的格式才可以。同时还要改变请求头信息。