I have a html form and that form has two fields (name , description). When a user hits submit button for that form I want to submit form data in json format.
I tried the following:
function submitData(){
payload.name = $("#project-name").val();
payload.description = $("#project-description").val();
$.post("http://localhost:5000/task-groups/add", payload);
return false;
}
Submitdata is called when my form's button is clicked. But this is sending form data and not json data
I have a python flask server running.
[1] When I do:
payload = request.get_json()
name = payload['name']
It is throwing the following exception
File "/Users/saik/projects/mturk/server/src/index.py", line 37, in add_task_group
name = payload['name']
TypeError: 'NoneType' object is not subscriptable
[2] However, I am able to access the data on the server side using following:
name = request.form['name']
Is it possible to send json data on form submit, so that I can access data using [1]
The reason I am trying to send JSON data on form submit is because I have a server which serves REST API for command line clients. And I would like to use same server and endpoint to serve browser based clients.