json
post方法将flask
格式的数据从网页发送到ajax
。我的尝试如下:我的尝试:mytest.html(代码段)
var jsondat = JSON.stringify(table.getData());
console.log(jsondat);
$.ajax({
type: 'POST',
url: '127.0.0.1:5000/test',
// contentType: 'application/json;charset=UTF-8',
data: {
'data': jsondat
},
success: function(response) {
alert("HELLO")
},
});
Flask App:
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/<string:page_name>/')
def render_static(page_name):
return render_template('%s.html' % mytest)
@app.route('/test')
def testfun():
content = request.get_json(silent=True)
print(content)
return 'The test'
if __name__ == '__main__':
app.run()