jQuery never returns - callback function never fires

321
March 13, 2017, at 4:20 PM

I previously posted this issue on stackoverflow, but I had simplified it so it could be easier to understand and answer : this was a really bad move as I got totally inadequate answers.

I'm trying to program a Discord Javascript bot using NodeJS. The purpose of this bot is to fetch content from DeviantArt, using their OAuth2 client_id/client_secret authentification method.

My problem is that once the jQuery request is sent, it never goes back and the callback function is never called : so I cannot know what failed because the "status" var stays blank.

var jsdom = require("jsdom").jsdom;
var doc = jsdom();
var window = doc.defaultView;
var $ = require('jquery')(window);
var jsonFinal = '';
var token_url = 'https://www.deviantart.com/oauth2/token';
$.get( token_url, { grant_type: 'client_credentials', client_id: 5946, client_secret: 'whatever'} ).done(function( data ) {
        jsonFinal = "("+data.status+data.error+")\n"+data;
        console.log(jsonFinal);
    });

(I'm using jsdom and jquery on nodeJS 6)

I followed the DA API documentation and I'm pretty sure that these are the right values to send to their server and that this is the right way to send them.

However, the console.log() in this code is never triggered.

How ? Why ?

Answer 1

Your problem is probably that you shouldn't put a function as an argument in your done function. But just in case there is some other problem try this:

var jsdom = require("jsdom").jsdom;
var doc = jsdom();
var window = doc.defaultView;
var $ = require('jquery')(window);
var jsonFinal = '';
var token_url = 'https://www.deviantart.com/oauth2/token';
$.get( token_url, {
    grant_type: 'client_credentials',
    client_id: 5946, 
    client_secret: 'whatever'
})
.done(function(data) {
    console.log(data);
    jsonFinal = "("+data.status+data.error+")\n"+data;
    console.log(jsonFinal);
})
.fail(function(error) {
    console.log(error);
})
.always(function() {
    console.log("done");
});
Rent Charter Buses Company
READ ALSO
Installing and using React

Installing and using React

I have spent a long time simply trying to install React and React-DOM

489
NodeJS can't take my DB values for my template

NodeJS can't take my DB values for my template

I started to develop a little web site in NodeJS, with admin authentication based on https://githubcom/DanialK/Simple-Authentication, it work very well

351
check req.body.property.childProperty inside req.checkBody()

check req.body.property.childProperty inside req.checkBody()

In nodejs we commonly do something like:

393
NodeJS AWS Lambda ListObject returning empty array

NodeJS AWS Lambda ListObject returning empty array

I am new to AWSI am creating a Scheduled lambda function using NodeJS

506