Sunday, 12 March 2017

jQuery never returns - callback function never fires

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 ?



via Rackover

No comments:

Post a Comment