I'm trying to build a graph that dynamically gets updated on click using d3.js and flask. But I'm having trouble passing json from d3.js to flask. I need to pass a json from d3 to flask to fetch new data based on the existing values. But I'm unable to pass json data. Here is my html code:
json_data = {
'name' : abc,
'position' : 2
};
d3.json("/get-next/"+json_data, function(error, d) {
console.log("new_data",d)
})
When I've tried to print it in my python code, it just prints [object object]. Even if I add JSON.stringify(json_data) it just prints [object object] on the server side.
Here is my .py file:
@application.route("/get-next/<jsdata>", methods=['GET', 'POST'])
def get_child(jsdata):
print(jsdata) # gives [object object]
#return new data based on jsdata
return json.dumps(new_data)
jsdata['name'] gives an error saying indices can be only integers.I've also tried using AJAX call. But that is not recognizing the route itself. Is there is a possibility to achieve this without AJAX ? If not can you please provide me with the AJAX solution ?