Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

testy's avatar

Vue-Resource Post-Request no data

I try a POST Request with Vue-Resource (with data):

Vue.http.post('subscribe', {email: this.email, hp: this.address}).then((val) => {
       console.log(val);
});

But if i try to print_r($_POST), there is an empty array.

If i do this with jquery:

$.ajax({
        url: 'subscribe',
        type: 'post',
        data: {
          email: 'email',
          name: 'name'
        }
      }).done(function(val) {
        console.log(val);
      })

It works fine :/

0 likes
4 replies
stevetrader's avatar

Had the exact same issue today and I worked on it for quite a while. Here is the solution:

http: {
    emulateJSON: true,
    emulateHTTP: true
}
2 likes
fabricecw's avatar

Into the Vue instance:

For example:

new Vue({
    
    http: {
            emulateJSON: true,
            emulateHTTP: true
    }

    // ...

})
1 like
xit21's avatar

new Vue({

el: '#root',

data: {
    newName: '',
    nameList: []
},

methods: {
    addName(){
        this.nameList = this.nameList.concat(this.newName);
        var name = this.newName;
        this.newName = '';

        this.$http.post('/api/name', {name: name}).then((response) => {
            console.log(response.message);
        });
    }
},

mounted(){
    this.$http.get('/api/name').then((response) => {
        this.nameList= this.nameList.concat(JSON.parse(response.body));
        console.log(this.nameList);
    });
}

});

this.$http.post(....) does not work. Any help would be appreciated?

Please or to participate in this conversation.