Skip to content

Instantly share code, notes, and snippets.

@blackrez
Created November 27, 2012 11:06
Show Gist options
  • Save blackrez/4153666 to your computer and use it in GitHub Desktop.
Save blackrez/4153666 to your computer and use it in GitHub Desktop.
jsonp demo
import json
from flask import Flask
from flask import request
app = Flask(__name__)
app.debug = True
@app.route('/')
def hello_world():
callback = request.args.get('jsoncallback')
data = {"hello":"world"}
if callback:
return callback + '(' + json.dumps(data) + ')'
else:
return json.dumps(data)
if __name__ == '__main__':
app.run()
@blackrez
Copy link
Author

Code js for testing :

$.getJSON("http://localhost:5000/?jsoncallback=?",
  function(data){console.log(data.hello)}
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment