flask app中從前端接受json的數(shù)據(jù),但是flask的request中并沒有接受成功,其中沒有數(shù)據(jù),換了很多函數(shù)都行不通。js代碼$(function(){ $("#test").click(function(){ $.ajax({ url: "{{ url_for('main.getjson') }}", type: "POST", data: JSON.stringify({ "n1": "test1", "n2": "test2", "n3": "test3" }), dataType: "json", success: function(data){ var a = data.user var texthtml = "<p>" + a + "</p>" $("#result").html(texthtml) } }); });});flask中的視圖函數(shù):@main.route('/getjson', methods = ['GET', 'POST'])def getjson(): a = request.json if a: return jsonify(user = "Right") return jsonify(user = "error")僅僅判斷request.json是不是存在,但是返回來的總是“error”的字符串。request.json中總是null。后來換了request.args.get(),同樣行不通。到底是哪里出錯了,真心求教。
怎么從flask中接受從jquery發(fā)送的json數(shù)據(jù)?
桃花長相依
2018-11-15 14:10:18