2014-11-03 3 views
2

나는jQuery를 AJAX 호출 - 응답 상태 설명 캐릭터 세트

문제는 인코딩입니다 (아래 코드 참조) 호출 내 아약스에 사용자에게 오류 메시지를 넣어 Response.StatusDescription을 사용하기 시작했습니다. 응답 메시지는 악센트 부호가있는 문자에 문제가 있습니다 (아래 AJAX 호출 참조).

내 PC에서 제대로 작동하지만 일단 서버에 게시되면이 문제가 발생하기 시작합니다.

내가 잘못 했나요?

public JsonResult MyAction(int variable) 
{ 
    if (variable > 0) 
    { 
     //Do Something 
    } 
    else 
    { 
     Response.StatusCode = (int)HttpStatusCode.Unused; 
     Response.StatusDescription = "Dados Inválidos"; //notice the 'á' on the message 
    } 
    return Json(true); 
} 

그리고 내 Ajax 호출 :

$.ajax({ 
    type: 'POST', 
    traditional: true, 
    url: '/testUrl/MyAction', 
    dataType: "JSON", 
    data: { 
     variable: myVal 
    } 
}) 
    .done(function() 
    { 
     //Do something 
    }) 
    .fail(function(error, textStatus, errorThrown) 
    { 
     var msg = error.statusText; //The message received is: "Dados InvÂilidos" 
     if (error.status !== 306) //HttpStatusCode.Unused 
      msg = 'Error occurred'; 

     this.dialogShowError(msg); 
    }); 

UPDATE : 이 내가받은 응답 헤더는이 :

enter image description here

문제는 Ajax 요청에 일어날 것으로 보인다. Regular ActionResult에 대한 테스트를했고 StatusDescription이 잘 설정되었습니다.

답변

0

Response.Charset = "utf-8"; 

내 직감이 HTTP 응답 헤더에 잘못된 문자 집합을 가지고있다보십시오.

+0

제안 사항을 추가했지만 여전히 동일한 문제가 발생합니다. 응답 헤더를 사용하여 업데이트하십시오. – HobojoeBr