jamiemax
jamiemax

Reputation: 189

jQuery ajax - xhr.responseText always undefined

I am attempting to debug a jQuery call to an API, however xhr.responseText always seems to be undefined. What changes would I need to make to this code to see details of the error?

jQuery.ajax({
    url: 'http://fusion-api-user.dev/api/v1/user/authorise/' + currentVideoItem.id + '/play',
    async: async,
    beforeSend: function(xhr){
        xhr.setRequestHeader('X-Forwarded-Host', 'fusion.dev');
    },
    xhrFields: {
        withCredentials: true
    },
    success: function (res, status, xhr) {
        currentVideoItem.authModule.playWithToken(xhr.getResponseHeader("X-Token"), "ais");
        alert('xhr: ' + xhr);
        alert('token:' + xhr.getResponseHeader('X-Token'));

        jQuery(currentVideoItem.parentContainer).trigger('video-authorized', [{
            id: currentVideoItem.id
        }]);
    },
    error: function(xhr, status) {
        alert("readyState: " + xhr.readyState + "\nstatus: " + xhr.status);
        alert("responseText: " + xhr.responseText);
        jQuery(window).trigger('countdown-session-ended', [{
            name: 'video', 
            trigger: 'authorizePlayError'
        }]);
    }
});

Upvotes: 1

Views: 947

Answers (1)

jamiemax
jamiemax

Reputation: 189

I figured this out by adding a callback function and calling it within the success function, like so:

success: function (response) {
//
    callback(response);
//
},

Upvotes: 1

Related Questions