axios post for multiple data with flask and vuejs
axios post for multiple data with flask and vuejs
All I want to do is get context_answers
and treatment_answers
from my web user inputs and bring it on the Flask. (I am very new to this, sorry that I am a vague about what I am doing)
context_answers
treatment_answers
`context_answers = "a":[1], "b":[2], "c":[3], "d":[4]
treatment_answers = "y":[10]`
I was able to get context_answers doing following:
`methods:
handleSubmit()
axios.post("/submit_survey", this.context_answers)
`
and on the Flask
`@app.route("/submit_survey", methods=["POST"])
def submit_survey():
context = request.get_json(force=True)
context_df = pd.DataFrame.from_dict(context)`
But how do you get this.treatments_answers
in the same axios post method? and in the submit_survey
?
this.treatments_answers
submit_survey
I want to create a data frame that has following:
a b c d y
1 2 3 4 10
a b c d y
1 2 3 4 10
Thank you so much!
context_answers
treatments_answers
1 Answer
1
If do you want past many params you can do this:
methods:
handleSubmit()
axios.post("/submit_survey", context_answers: this.context_answers,
treatments_answers: this.treatments_answers)
.then(
(response) => console.log(response) ,
(error) => console.log(error)
)
or try this:
methods: {
handleSubmit()
axios.post("/submit_survey", context_answers: this.context_answers,
treatments_answers: this.treatments_answers)
.then(response =>
console.log(response)
)
.catch(error =>
console.log(error)
);
Thank you David. Then how do I request later? I know it is super basic.
– user9307178
Sep 10 '18 at 5:30
I mean when I had just one context_answer, I used
context = request.get_json(force=True)
to extract it and convert it into pandas data frame. So now how do I save the treatment now?– user9307178
Sep 10 '18 at 5:37
context = request.get_json(force=True)
in theory you should capture the axion in a variable just like this:
const response = await axios.post( ...
then make a console.log of response and tell me what you see– David Leonardo Molina Ruiz Dav
Sep 10 '18 at 12:56
const response = await axios.post( ...
Promise <pending> __proto__ : Promise catch : ƒ catch() arguments : (...)
– user9307178
Sep 10 '18 at 15:26
Promise <pending> __proto__ : Promise catch : ƒ catch() arguments : (...)
I edited my answer, look how the method handleSubmit was, make a console.log of response again and tell me what you see
– David Leonardo Molina Ruiz Dav
Sep 10 '18 at 15:38
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
It's unclear what you're asking. Perhaps show an example of each piece of data (ie
context_answers
andtreatments_answers
) and what you'd like the received data to look like in your Flask app– Phil
Sep 10 '18 at 3:53