Skip to content
Advertisement

Can’t return multiple variables from Flask to Javascript AJAX function

I have a JS function that is updating subsequent select boxes based on the previous input. I am populating these with responses from a Flask function that queries a database. The issue is that the second variable that holds an array cannot be processed properly. The first function works fine, but the second just has an undefinded variable.

JS Function

JavaScript

Flask Function

JavaScript

I tried passing the variable through the first function to see if it would be accepted but it didn’t. The first function has it set to a string ‘success’. The second function returns ‘undefined’.

Thanks in advance for any help.

Advertisement

Answer

The answer is to create a JSON object within the flask function and return it as one varibale as well as only using one JS function. I am not sure of the reasoning behind it as I guess I don’t understand JSON and AJAX etc. very well. Flask

JavaScript

js

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement