首页 > 解决方案 > Ajax responseText和statusText在不同服务器上不同

问题描述

我在 ASP.NET MVC 中有一个项目,其中在一个动作中我返回以下内容:

public ActionResult MyAction()
{
       return new HttpStatusCodeResult(HttpStatusCode.NotFound, "custom err msg");
} 

这个响应被发送到 ajax 函数并被 fail() 函数捕获:

$.ajax({
    url: "url to MyAction",
    type: 'POST',
    contentType: "application/json; charset=utf-8",
    dataType: "json"
  })
  .fail(function (data) {
    console.log(data); 
   });
});

当我在本地 IIS Express 上通过 Visual Studio 运行它时,console.log(data) 返回:

responseText
:
"some html with my 'custom err msg' inside it"
status
:
404
statusText
:
"error"

但是在我的 Azure 开发服务器上:它 console.log(data) 返回:

responseText
:
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
status
:
404
statusText
:
"custom err msg"

为什么会这样不一致?以及在两台服务器中可以做什么,或者我的错误消息在 responseText 或 statusText 中

标签: c#jqueryajaxasp.net-mvchttp

解决方案


HTTP/2 中不再存在状态行。也许服务器正在运行不同版本的 HTTP?

(另外,fwiw,应用程序/json 上没有字符集参数)


推荐阅读