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!






It's unclear what you're asking. Perhaps show an example of each piece of data (ie context_answers and treatments_answers) and what you'd like the received data to look like in your Flask app

– Phil
Sep 10 '18 at 3:53


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.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)