jqXHR
객체에 추가 필드를 전달할 방법이 있습니까? 여기 내 상황 :AJAX jqXHR에 사용자 정의 필드 전달
내가 돌아 해요 HttpResponseMessage
과 같이 :
response.ReasonPhrase = "someString " + Resources.Messages.NoData;
response.StatusCode = HttpStatusCode.NoContent;
return response;
하지만 다른 이유로, 다른 StatusCode = HttpStatusCode.NoContent;
을 통과 할 몇 가지 경우가 같습니다 때문에
response.ReasonPhrase = "anotherString " + Resources.Messages.NoMoreData;
response.StatusCode = HttpStatusCode.NoContent;
return response;
가 메시지가 모두 사용자 언어로 현지화되었으므로 (Resources.Messages
) "someString "
또는 "anotherString "
또는 AJAX
의 "...."과 같으면 추가 필드가 필요합니다. 다시통화 :
$.ajax({
type: 'POST',
url: '/api/testing/test',
data: jobject,
contentType: 'application/json',
success: function (data, status, xhr) {
if (status == "nocontent" && xhr.statusText.startsWith("someString")) {
// do something
}
if (status == "nocontent" && xhr.statusText.startsWith("anotherString")) {
// do something
}
error: function (xhr) {
debugger;
if (xhr.responseJSON == 'UnableToParseDateTime') {
// do something
}
}
});
, xhr.statusText
이 xhr.statusText.startsWith()
을 지원하지 않는다는 것입니다. 따라서 "someString "
또는 "anotherString "
또는 "...."에 대한 등호 검사가 작동하지 않습니다.
나는 responseText
이 (가) success
콜백에서 항상 비어있는 것으로 나타났습니다. 만약 내가 '채울 수'그 서버에서 좋은 것입니다. 그렇지 않다면 jqXHR
개체에 대한 추가 필드를 어떻게 가질 수 있습니까? 또는 몇 가지 새로운 사용자 정의 HttpStatusCode
을 정의 할 수 있습니까? startsWith
표준 자바 스크립트의 경우
asp.net-webapi를 사용하여 jqXHR에 사용자 정의 필드의 예가 있습니까? 나는 예. 그렇지만 AJAX에 관한 모든 것을 읽지는 않습니다. – Quoter