c# - 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 中
解决方案
HTTP/2 中不再存在状态行。也许服务器正在运行不同版本的 HTTP?
(另外,fwiw,应用程序/json 上没有字符集参数)
推荐阅读
- flutter - 如何在 Flutter Firestore 提供程序中显示数据
- kotlin - InputStream getResource() 返回 NULL
- jenkins - Linux:找不到回退包文件夹“C:\Program Files\dotnet\sdk\NuGetFallbackFolder”
- javascript - Google Sheets JavaScript - TypeError:无法读取未定义的属性“getSheetName”
- acumatica - 支票和付款出现空“发票日期”错误
- python - 从具有嵌套结构的字典中删除混合数据类型的空值和空对象
- domain-driven-design - 基于AOP的业务规则分离
- sql - 为什么交替查询过滤器顺序没有给我相同的结果
- python - Docker compose 从 .env 文件中获取环境变量并传递给 docker build
- gentics-mesh - 如何指定要从 Gentics Mesh 查询的模式(或索引)(无 graphQL API)