ajax接收flask传递的json数据

时间:2024-01-19 20:09:14
from flask import Flask, request
import json app = Flask(__name__) @app.route('/')
def func():
res = {
'data': {
'data1': [],
'data2': []
}
} callback = request.values.get('callback')
return ''.join([
callback,
'(',
json.dumps(res),
');'
]) if __name__ == '__main__':
cfg = {
'host': '0.0.0.0',
'port': 1234,
'debug': True
}
'''
// javascript code:
$.ajax({
url: "http://localhost:1234/",
dataType: "jsonp",
data: {},
success: function(res) {
console.log(res);
}
});'''
app.run(**cfg)

原文:http://gsw945.com/temp/flask-jsonp.py