Ich lerne, wie Ajax verwenden und Flask, also was ich tue, ist ich eine Ajax-Anforderung senden und ich erhalte die Daten als post
Anfrage in meiner Python-Dateiwie in Daten von ‚ImmutableMultiDict‘ erhalten Kolben
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);
}
});
und meine python-Datei enthält:
@app.route('/post/data',methods=['GET','POST'])
def postdata():
#do some
data = str(request.args)
json_dumps = json.dumps(data)
return json_dumps
das gibt mir Daten auf der Seite folgende
"ImmutableMultiDict([('{\"name\":\"John Doe\",\"age\":\"21\"}', u'')])"
Und das ist, was mein request.query_string
{%22name%22:%22John%20Doe%22,%22age%22:%2221%22}
sieht ja, wie bekomme ich die name
und age
. Bitte korrigieren Sie mich Wenn ich irgendwo falsch liege. Vielen Dank im Voraus.
Verwenden Sie 'request.json.get ('Name')' – kartheek