Discourse ajax promise problem


(Joe Seyfried) #1

I came across something weird: I do a

Discourse.ajax("/my/route/").then(function(result){

and have the promise never returned. If I add a

.bind(this)).catch(function(x){
            console.error(x);
        });

to the anonymous function definition, I receive an

Object {readyState: 4, getResponseHeader: function, getAllResponseHeaders: function, setRequestHeader: function, overrideMimeType: function…}

…on the console - filled with all the stuff I was waiting for! Is Discourse trying to do something funny with my data, does it have to be in a special format, rendered specifically?


Promises broken by an iframe…
(Robin Ward) #2

Is /my/route returning JSON?

Ajax will say a promise fails if the format returned is not what was expected. You may be returning HTML, or perhaps JSON just with the wrong content-type.


(Joe Seyfried) #3

*groan* that’s it. Thought I could just pipe plain text for a single data element… Thanks.


(Régis Hanol) #4

(Kane York) #5

Try Discourse.ajax("/my/route/", {data-type: "text"})"