T
T
tarasikgoga2017-06-11 15:06:30
JavaScript
tarasikgoga, 2017-06-11 15:06:30

VueJs how to send a post request with parameters?

Send request like this

this.$http.post('http://localhost:3000/store', {something: 'string'}, {
          headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
          }})

and if you look through the browser, then the parameters look like this
b487f28b5dcf4aa29cc07541399e0fb6.png
. Note that my object is the key of another object
(if you use json.stringfy(), then my object will still be the key of another object)
Why did it happen and how to make a normal object?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Fetur, 2017-06-11
@Fetur

I don't know VueJs, but there is an alternative - the old-fashioned XMLHttpRequest or $.post. Why this sugar, which does not sweeten, but only makes you look at what has already been done many years ago. How long will there be stupid questions on the toaster "How to send a post request" of which there are already more than 680. Ridiculous.
Tell me, how is your post different from my two options? I'm guessing nothing.

A
Archakov Dennis, 2017-06-11
@archakov06

Your question is not very clear. Key of another object?
If you want the value that is in the something variable to be driven in instead of the something key, then you need to create an object in the variable and then pass this variable (object) to the request.

var data = {};
var something = 'test_key';
data[something] = 'string';
this.$http.post('http://localhost:3000/store', data, ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question