vini vini - 5 months ago 39
jQuery Question

Deferred jquery 201 Post created going in reject

postData: function (url, data) {
var deferred = Q.defer();

type: 'POST',
url: url,
data: JSON.stringify(data),
dataType: "json",
beforeSend: function (xhr, settings) {
xhr.setRequestHeader('Authorization', 'Bearer ' + window.access_token);
xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
success: function (data, responseText, jqXHR) {
deferred.resolve(data, responseText, jqXHR);
error: function (e) {

return deferred.promise;

I don't understand why my request is going inside error callback

enter image description here


Based on comments that you are returning html you need to set appropriate dataType

$.ajax will also go to error if there is a parse error of the requested dataType. You can confirm this by logging the arguments of the error handler error: function (xhr, statusText, errorThrown)

Try changing




Or remove that property as jQuery will know from the Content Type header