Question

I'm using jQuery.when to make two ajax requests, looking at firebug the requests are being made and seem to return the correct data with a status code of 200 but the fail callback is being executed instead of the done callback. what am I doing wrong?

function method1() {
    return $.ajax("/queryapp/query/asset-graph-data", {
        data: {
            assetId: 'e886c48b-77f9-4577-ab7b-b1c7245e2746'
        },
        dataType: 'application/json',
        headers : { 'X-Authentication' : authValue, 'X-Tenant' : 'cfd' }
    })
    .done(function(){
        console.log('1');
    })
    .fail(function(){
       console.log('fail 1');
    });
}

function method2() {
    return $.ajax("/queryapp/query/asset-graph-data", {
        data: {
            assetId: 'e886c48b-77f9-4577-ab7b-b1c7245e2746',
            start: '3445455',
            end: '90000'
        },
        dataType: 'application/json',
        headers : { 'X-Authentication' : authValue, 'X-Tenant' : 'cfd'}
        })
        .done(function(){
            console.log('2');
        })
        .fail(function(){
            console.log('fail 2');
        });
    }

    $.when(method2(), method1()).done(function (r1, r2) {
        var test = 'ksks';
    })
Was it helpful?

Solution

dataType should be "json", not 'application/json'. I think that's where the trouble lies.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top