繁体   English   中英

app_offline.htm不返回对ajax请求的响应

[英]app_offline.htm doesn't return response to ajax request

我创建了一个文件app_offline.html,内容:

{
   "ServerUnavailable":"true",
   "IssueType":"Maintenance",
   "ErrorMessage":"Servers are currently down for maintanance, please try again later"
}

并发布到我的服务器。

我想从我的应用程序中显示有关服务器停机的消息。

当我通过谷歌浏览器导航到服务器时,我看到:

在此处输入图片说明

好的,一切都很好。

但是当我从我的应用程序发出ajax请求时:

$.ajax({
  // bla bola bla
})
.done(function (response, textStatus, jqXHR) {
  // bla bola bla
})
.fail(function (XMLHttpRequest, textStatus, errorThrown) {
  // HERE I WANT TO DISPLAY A MESSAGE
});

未定义XMLHttpRequest的所有属性。 我已经尝试了所有:

response responseBody responseType responseXML responseJSON status statusText

在哪里可以找到在浏览器中看到的响应? 还是我想念什么?

由于请求没有失败,因此该代码实际上永远不会进入失败功能。

当您请求app_offline.html文件时,它只会退还给您

{
   "ServerUnavailable":"true",
   "IssueType":"Maintenance",
   "ErrorMessage":"Servers are currently down for maintanance, please try again later"
}

它不会产生任何错误,并将存储在.done函数的“ response”变量中。

我认为您忽略了Http Header的要求。 标头应为Content-Type: application/json但您使用的是html文件,因此IIS使用text/html标头提供此文件。

看看这个https://www.iis.net/configreference/system.webserver/staticcontent/mimemap

<configuration>
   <system.webServer>
      <staticContent>
         <mimeMap fileExtension=".syx" mimeType="application/octet-stream" />
         <mimeMap fileExtension=".tab" mimeType="text/plain" />
      </staticContent>
   </system.webServer>
</configuration>

在应用此功能之前,您可能需要更改文件的扩展名。 这样可能会更容易。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM