I’m trying to figure out how to send multiple fields with AJAX. Would I use a GET or POST?
I’m using Python Server Pages. I want my fields to update based on what option is selected in a select box – as far as I know I’ve gotten that to work so far, I’m just wondering how to send multiple discrete pieces of data via XMLHttpRequest.
i.e.
fname = c.execute("""SELECT fname from employees WHERE user = %s;""", (uname))
lname = c.execute("""SELECT lname from employees WHERE user = %s;""", (uname))
email = c.execute("""SELECT email from employees WHERE user = %s;""", (uname))
deptid = c.execute("""SELECT dept_id from employees WHERE user = %s;""", (uname))
active = c.execute("""SELECT active from employees WHERE user = %s;""", (uname))
sentient = c.execute("""SELECT sentient from employees WHERE user = %s;""", (uname))
I would have all of these pieces of data, and want to send them back to my other page. How would I do this, so that it is updated async?
Note, I want to send this FROM the server TO the client page. I.e. all of these fields will be sent back to my main page and displayed to the user, if the user selects a different username from a select box on the client page (which is not show here and which will be sent via a POST or GET)
While I’m not familiar with Python, I’d bet that there is a way to serialize your data to JSON to return to the client.
On the client side, you’d then be able to traverse the data like you would any other javascript object: