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