I am learning how to use ajax and Flask ,so what I do is I send a ajax request and I receive the data as post
request in my python file
My html file contains this code
var data = {"name":"John Doe","age":"21"};
$.ajax({
url:'/post/data',
datatype : "json",
contentType: "application/json; charset=utf-8",
data : JSON.stringify(data),
success : function(result) {
jQuery("#clash").html(result);
},error : function(result){
console.log(result);
}
});
And My python file contains :
@app.route('/post/data',methods=['GET','POST'])
def postdata():
#do some
data = str(request.args)
json_dumps = json.dumps(data)
return json_dumps
This gives me following data on the page
"ImmutableMultiDict([('{\"name\":\"John Doe\",\"age\":\"21\"}', u'')])"
And this is what my request.query_string
looks {%22name%22:%22John%20Doe%22,%22age%22:%2221%22}
So how do I get the name
and age
. Please correct me If I am wrong anywhere.Thanks in advance.