Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

275
Views
Cross domain Angular JSONP request to Python Bottle

I'm trying to do a cross-domain JSONP request with AngularJS to Bottle, but I'm getting an 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);
});

Bottle:

@route('/test')
def test():
    response.headers['Content-Type'] = 'application/json'
    return json.dumps({"random": "JSON"})

Error:

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You need to return an JavaScript application (wrapper function in this case) not an json object. This site explains you the basics of JSONP handling.

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"))
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!