Estoy tratando de hacer una solicitud JSONP entre dominios con AngularJS a Bottle, pero recibo un error.
Angular:
// this angular code is on localhost:8888, so it's cross domain var URL = "http://localhost:8000/test"; URL = $sce.trustAsResourceUrl(URL); $http.jsonp(URL, {jsonpCallbackParam: 'callback'}) .then(function successCallback(response) { console.log(response); }, function errorCallback(error) { console.log(error); });
Botella:
@route('/test') def test(): response.headers['Content-Type'] = 'application/json' return json.dumps({"random": "JSON"})
Debe devolver una aplicación JavaScript (función contenedora en este caso) no un objeto json. Este sitio le explica los conceptos básicos del manejo de JSONP .
def jsonp(request, dictionary): if (request.query.callback): # wrap the dictionary in the callback parameter return "%s(%s)" % (request.query.callback, dictionary) return dictionary @route('/test') if (request.query.callback): response.content_type = "application/javascript" return jsonp(dict(success="It worked"))