[英]app_offline.htm doesn't return response to ajax request
I have created a file app_offline.html, contents: 我创建了一个文件app_offline.html,内容:
{
"ServerUnavailable":"true",
"IssueType":"Maintenance",
"ErrorMessage":"Servers are currently down for maintanance, please try again later"
}
And posted to my server. 并发布到我的服务器。
From my app i want to show a message about server downtime. 我想从我的应用程序中显示有关服务器停机的消息。
When i navigate to my server via Google Chrome i see: 当我通过谷歌浏览器导航到服务器时,我看到:
Okay, all is cool. 好的,一切都很好。
But when i do a ajax request from my app: 但是当我从我的应用程序发出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
});
The XMLHttpRequest all properties are not defined. 未定义XMLHttpRequest的所有属性。 I have tried all: 我已经尝试了所有:
response responseBody responseType responseXML responseJSON status statusText response responseBody responseType responseXML responseJSON status statusText
Where i can find the response that i see in browser? 在哪里可以找到在浏览器中看到的响应? Or what am i missing? 还是我想念什么?
This code actualy never enters the fail function since the request didn't fail. 由于请求没有失败,因此该代码实际上永远不会进入失败功能。
When you request the app_offline.html file it will just give back 当您请求app_offline.html文件时,它只会退还给您
{
"ServerUnavailable":"true",
"IssueType":"Maintenance",
"ErrorMessage":"Servers are currently down for maintanance, please try again later"
}
Which doesn't generate any errors and will be stored in the "response" variable of your .done function. 它不会产生任何错误,并将存储在.done函数的“ response”变量中。
I think you are ignoring the Http Header requirements. 我认为您忽略了Http Header的要求。 The header should be Content-Type: application/json
but you are using a html file so IIS serves this file with text/html
header. 标头应为Content-Type: application/json
但您使用的是html文件,因此IIS使用text/html
标头提供此文件。
Take a look at this https://www.iis.net/configreference/system.webserver/staticcontent/mimemap 看看这个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>
Before you apply this you might want to change your file's extension. 在应用此功能之前,您可能需要更改文件的扩展名。 It might be easier this way. 这样可能会更容易。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.