2016-10-08 3 views
1
postData: function (url, data) { 
    var deferred = Q.defer(); 

    $.ajax({ 
     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) { 
      deferred.reject(e); 
     } 
    }); 

    return deferred.promise; 
} 

내 요청 오류 콜백 내부에가는 이유를 이해하지 않습니다 당신이 적절한 설정해야 당신이 HTML을 반환하는 의견을 바탕으로이연 JQuery와 201 포스트가는 거부 만든

enter image description here

+0

서버는 201을 처리합니다. – vini

+0

매우 이상합니다. '2xx' 응답 코드는'success'로 간주되어야합니다. –

+0

유효한 json을 반환 하시겠습니까? 구문 분석 오류가있는 경우 $ .ajax는 오류로 이동합니다. – charlietfl

답변

2

dataType

$.ajax 또한 요청 된 dataType의 구문 분석 오류가있는 경우 오류가 발생합니다. 당신은 오류 처리기의 인수를 기록하여 확인할 수 있습니다 error: function (xhr, statusText, errorThrown)

한번에 변경

dataType:'json' 

dataType:'html' 

또는 jQuery를이 컨텐츠 유형 헤더에서 알 수로 그 속성을 제거