Vue-resource: this.$http.post not works, it turn into get method.

Created on 1 Apr 2016  路  8Comments  路  Source: pagekit/vue-resource

i used this.$http({method: 'POST'}) to fix. but i hope "this.$http.post" can be used

Most helpful comment

This question was answerd here: https://github.com/vuejs/vue-resource/issues/15

All post data is send as application/json by default, if you want to send as form-data can enable this option

So in order for that to work, you need to set the emulateJSON option to true. For example:

this.$http.post('http://example.com', data, {emulateJSON:true}).then(function(res){
    // Do something with the response
});

All 8 comments

I have the same problem

I solved the problem for myself

i change root paramener:
from Vue.http.options.root = '/ajax'
to Vue.http.options.root = '/en/ajax'

it seems that the problem is not the plugin :)

This question was answerd here: https://github.com/vuejs/vue-resource/issues/15

All post data is send as application/json by default, if you want to send as form-data can enable this option

So in order for that to work, you need to set the emulateJSON option to true. For example:

this.$http.post('http://example.com', data, {emulateJSON:true}).then(function(res){
    // Do something with the response
});

Why was this closed? I am getting the same issue, and I don't see a proper solution. If I use this.$http.post I expect to see a POST request being sent out, not a GET request.

  • The OP did not provide a reproduction, nor did he provide any code to reproduce the problem properly.
  • He also did not provide the version he used.
  • Nonetheless, someone provided an answer.
  • The OP did not react after an answer was provided.

Why should we leave the issue open after two months?

If you see this problem, please provide a reproduction, with the concrete version that was used.

Fair enough! I notice this only happens on urls without FQDNs and without http/https scheme

http://jsfiddle.net/vjvMp/568/

http://i.imgur.com/DahzRUw.jpg

Version 1.0.2

Thanks for this! We will look it!

I have the same problem:
this.$http.post('/api/autos', this.formatFormData()) - send GET request

The problem was solved by adding / to the end of request url
this.$http.post('/api/autos/', this.formatFormData()) - send POST request

Was this page helpful?
0 / 5 - 0 ratings