简体   繁体   中英

app_offline.htm doesn't return response to ajax request

I have created a file app_offline.html, contents:

{
   "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({
  // 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. I have tried all:

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

{
   "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.

I think you are ignoring the Http Header requirements. The header should be Content-Type: application/json but you are using a html file so IIS serves this file with text/html header.

Take a look at this 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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