-
-
Save skovhus/6218772 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import wraps | |
from flask import request, current_app, jsonify | |
def support_jsonp(f): | |
"""Wraps output to JSONP""" | |
@wraps(f) | |
def decorated_function(*args, **kwargs): | |
result = jsonify(f(*args, **kwargs)) | |
callback = request.args.get('callback', False) | |
if callback: | |
content = str(callback) + '(' + str(result.data) + ')' | |
return current_app.response_class(content, | |
mimetype='application/json') | |
else: | |
return result | |
return decorated_function | |
# then in your view | |
@app.route('/test/<task_id>', methods=['GET']) | |
@support_jsonp | |
def test(id): | |
return {"foo": "bar", "id": id} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi all , how can I get the reponse of the web service in a php callback function