Home $.ajax deferred issue: Object doesn't support property or method 'then'
Reply: 0

$.ajax deferred issue: Object doesn't support property or method 'then'

Chris G.
1#
Chris G. Published in 2017-12-07 17:28:28Z

I'm trying to chain some ajax calls but I'm getting an "Object doesn't support property or method 'then'" error. I'm trying to send a chunk of data in one call, (hopefully) getting a unique value back, then sending that unique value to another call.

Here are my methods...

var fetchDocID = function() {   
            log('fetchDocID: ');
            // ajax call
            $.ajax({
                url: myUrl,
                method: 'POST',
                contentType: 'application/json; charset=utf-8',
                beforeSend: function (request) {
                    request.setRequestHeader("Authorization", "Negotiate");
                },
                crossDomain: true,
                dataType: 'json',
                processData: false,
                async: true,
                cache: false,
                data: '{\"Text\": \"'+myText+'\"}',             
                error: function (xhr, textStatus, errorMessage) {
                    console.log("fetchDocID Error: " + errorMessage);
                }
            });
}   

var fetchSuccess = function(response){
        console.log('fetchSuccess');      
        myDocID = response.documentID;
        console.log("myDocID: "+ myDocID);
        var qryDocID = myNewUrl + myDocID;
        return $.ajax(qryDocID);
}

I'm trying to use the following to chain it all together. This is where I'm getting the error...

fetchDocID.then(fetchSuccess).then(function(response){
    console.log("fetchDocID: " + JSON.stringify(response));
}).catch(onError);

I probably haven't had enough coffee today. But what am I doing wrong?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.331865 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO