dropWizard
dropWizard

Reputation: 3538

Callback hell help, writing a function inside a call back

I'm new to Javascript and trying to figure out how to properly write this.

$.get("https://localhost:8090/", function(response) {
    console.log(response) #this works as expected
    $.get("https://localhost:8090"+response), function() {
        console.log('response') #nothing is printed
    };
})

The response from $.get("https://localhost:8090/" is /oauth2callback. On my server (flask), I have logging enabled and I can see that the function inside the route is running properly.

The server code looks something like this:

@app.route('/oauth2callback')
def oauth2callback()    
    if 'code' not in flask.request.args:
        logging.warning('code not in args')
        auth_uri = flow.step1_get_authorize_url()
        logging.warning(auth_uri)
        return auth_uri

I can see in the log file that auth_uri is accurate.

However, I do not see console.log('response') being printed in my console. I assume this is due to my poor Javascript skills and not writing the callback correctly?

How should I structure this?

Thanks!

Upvotes: 1

Views: 54

Answers (1)

nem035
nem035

Reputation: 35491

You have an extra ) by mistake

$.get("https://localhost:8090"+response), function() {
// ....................................^ remove this paren
}); // <--- and add it here

Upvotes: 4

Related Questions