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

245
Views
How can I access the return value of a Flask route within a Javascript file?

The problem I'm having is accessing the value within the return statement in the flask route (resp["login"]). I'm trying to use this value in a javascript file and use it as a query parameter. But whenever i try the console.log() in the javascript file I get a promise object. But I am not able to find where I could find the value coming in from the Flask app. I thought it would be within the response object below but no such luck.

@app.route('/route', methods=['GET', 'POST'])
@cross_origin(supports_credentials=True)
def handle_callback():

    if request.method == 'POST':

        payload = {
            blahhh
        }
        headers = {'Accept': 'application/json', 'Access-Control-Allow-Origin': '*'}
        req = requests.post(token_url, params=payload, headers=headers)
        # make another request after this using access token with updated header field 
        resp = req.json()

        if 'access_token' in resp:
            oauthHeader = "token " + resp['blahhh']
            headers = {'Authorization': oauthHeader}
            access_token_url = 'https://blahhh.com'
            r = requests.get(url=access_token_url, headers=headers)
            resp = r.json()
            return resp["login"]
        else:
            return "error", 404
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const codeGit = urlParams.get('code')

const sub = {codeGit};
 

const res = fetch('http://localhost:4000/route', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Access-Control-Allow-Origin': '*',
        'code': codeGit
    },
    credentials: 'include'
}).then(response => {
    if(response.status == 200){
        console.log('Success! ' + response.json() )
    }
}).catch(error => {
    console.log('error with access token req!')
})

console.log(res)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

response.json() return a promise

Return value: A Promise that resolves to a JavaScript object. This object could be anything that can be represented by JSON — an object, an array, a string, a number...

.then(response => {
    if(response.status == 200){
        return response.json();
    } else {
        // handle this somehow
    }
}).then(json => {
    console.log('Success! ' + JSON.stringify(json))
}).catch(error => {
    console.log('error with access token req!')
})
about 4 years ago · Juan Pablo Isaza 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!