久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <legend id='BFxTV'><style id='BFxTV'><dir id='BFxTV'><q id='BFxTV'></q></dir></style></legend>
    <i id='BFxTV'><tr id='BFxTV'><dt id='BFxTV'><q id='BFxTV'><span id='BFxTV'><b id='BFxTV'><form id='BFxTV'><ins id='BFxTV'></ins><ul id='BFxTV'></ul><sub id='BFxTV'></sub></form><legend id='BFxTV'></legend><bdo id='BFxTV'><pre id='BFxTV'><center id='BFxTV'></center></pre></bdo></b><th id='BFxTV'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='BFxTV'><tfoot id='BFxTV'></tfoot><dl id='BFxTV'><fieldset id='BFxTV'></fieldset></dl></div>
  1. <small id='BFxTV'></small><noframes id='BFxTV'>

    • <bdo id='BFxTV'></bdo><ul id='BFxTV'></ul>

    1. <tfoot id='BFxTV'></tfoot>

      jQuery AJAX 在窗口卸載時觸發錯誤回調 - 如何過濾

      jQuery AJAX fires error callback on window unload - how do I filter out unload and only catch real errors?(jQuery AJAX 在窗口卸載時觸發錯誤回調 - 如何過濾掉卸載并只捕獲真正的錯誤?) - IT屋-程序員軟件開發技術
      <legend id='RfkGw'><style id='RfkGw'><dir id='RfkGw'><q id='RfkGw'></q></dir></style></legend>
      <i id='RfkGw'><tr id='RfkGw'><dt id='RfkGw'><q id='RfkGw'><span id='RfkGw'><b id='RfkGw'><form id='RfkGw'><ins id='RfkGw'></ins><ul id='RfkGw'></ul><sub id='RfkGw'></sub></form><legend id='RfkGw'></legend><bdo id='RfkGw'><pre id='RfkGw'><center id='RfkGw'></center></pre></bdo></b><th id='RfkGw'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='RfkGw'><tfoot id='RfkGw'></tfoot><dl id='RfkGw'><fieldset id='RfkGw'></fieldset></dl></div>
          <tbody id='RfkGw'></tbody>

            <bdo id='RfkGw'></bdo><ul id='RfkGw'></ul>

            <small id='RfkGw'></small><noframes id='RfkGw'>

                <tfoot id='RfkGw'></tfoot>
                本文介紹了jQuery AJAX 在窗口卸載時觸發錯誤回調 - 如何過濾掉卸載并只捕獲真正的錯誤?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                如果我在 $.ajax() 請求中間離開頁面,它會觸發錯誤回調.我已經在 Safari 和 FF 中測試了 GET 和 POST 請求.

                If I navigate away from a page in the middle of an $.ajax() request it fires the error callback. I've tested in Safari and FF with both GET and POST requests.

                一種可能的解決方案是在頁面卸載時中止所有 AJAX 請求,但在卸載之前調用錯誤處理程序,因此這似乎是不可能的.

                One potential solution would be to abort all AJAX requests on page unload, but the error handler is called before unload, so this doesn't seem possible.

                我希望能夠通過禮貌警報或模式對話框在客戶端優雅地處理諸如 500 之類的真實錯誤,但我不希望在用戶離開頁面時調用此處理.

                I want to be able to handle REAL errors such as 500s gracefully on the client side with a polite alert or a modal dialog, but I don't want this handling to be called when a user navigates away from the page.

                我該怎么做?

                --

                (也很奇怪:當導航離開頁面時,錯誤處理程序說 textStatus 參數是錯誤",它在接收 500/bad 請求時拋出相同.)

                (Also strange: When navigating away from a page, the error handler says that the textStatus parameter is "error", the same it throws when receiving a 500/bad request.)

                推薦答案

                在錯誤回調或$.ajax 你有三個輸入參數:

                In the error callback or $.ajax you have three input arguments:

                function (XMLHttpRequest, textStatus, errorThrown) {
                   this; // options for this ajax request
                }
                

                可以直接查看xhr.status獲取HTTP響應碼,例如:

                You can check directly the xhr.status to get the HTTP response code, for example:

                $.ajax({
                  url: "test.html",
                  cache: false,
                  success: function(html){
                    $("#results").append(html);
                  },
                  error: function (xhr, textStatus) {
                    if (xhr.status == 500) {
                      alert('Server error: '+ textStatus);
                    }
                  }
                });
                

                區分瀏覽器斷開的連接和服務器關閉的情況(jasonmerino 的評論):

                To tell the difference between a connection broken by the browser and the case where the server is down (jasonmerino's comment):

                卸載時 xhr.readyState 應為 0,其中表示無響應服務器的 xhr.readyState 應該是 4.

                On unload the xhr.readyState should be 0, where for a non responsive server the xhr.readyState should be 4.

                這篇關于jQuery AJAX 在窗口卸載時觸發錯誤回調 - 如何過濾掉卸載并只捕獲真正的錯誤?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調用 abort (jQuery) 之后,瀏覽器也會等待 ajax 調用完成)
                JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標頭) - IT屋-程序員軟件開發技術分
                Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (301 302))
                NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內容)

                  <small id='y7Dgo'></small><noframes id='y7Dgo'>

                • <legend id='y7Dgo'><style id='y7Dgo'><dir id='y7Dgo'><q id='y7Dgo'></q></dir></style></legend>
                    • <i id='y7Dgo'><tr id='y7Dgo'><dt id='y7Dgo'><q id='y7Dgo'><span id='y7Dgo'><b id='y7Dgo'><form id='y7Dgo'><ins id='y7Dgo'></ins><ul id='y7Dgo'></ul><sub id='y7Dgo'></sub></form><legend id='y7Dgo'></legend><bdo id='y7Dgo'><pre id='y7Dgo'><center id='y7Dgo'></center></pre></bdo></b><th id='y7Dgo'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='y7Dgo'><tfoot id='y7Dgo'></tfoot><dl id='y7Dgo'><fieldset id='y7Dgo'></fieldset></dl></div>

                          <bdo id='y7Dgo'></bdo><ul id='y7Dgo'></ul>
                            <tbody id='y7Dgo'></tbody>

                          <tfoot id='y7Dgo'></tfoot>
                          主站蜘蛛池模板: 日韩免费一级 | 国产精品久久久久久久久久久免费看 | 亚洲人在线播放 | 全免费a级毛片免费看视频免 | 久久99精品久久久久久 | 国产精品九九视频 | 欧美 日韩 国产 成人 在线 | 视频三区 | 黑人成人网 | 国产ts人妖另类 | 免费在线观看av的网站 | 日韩精品一区二区三区中文在线 | 欧美日韩高清在线一区 | 亚洲二区视频 | 91国内外精品自在线播放 | 美女一级a毛片免费观看97 | 国产97人人超碰caoprom | 97精品视频在线 | 久草福利| 成人精品视频99在线观看免费 | 91国内精品久久 | 久久国 | 国产综合区 | 亚洲热在线视频 | 国内精品久久久久久久影视简单 | 曰韩一二三区 | 欧美精品一区二区三区蜜桃视频 | 欧美精品欧美精品系列 | 日本天堂视频在线观看 | 欧美激情在线一区二区三区 | 欧美成人免费在线视频 | 成年免费在线观看 | 亚洲国产一区二区三区 | 99热在线播放 | 中文字幕成人av | 成人区精品| 9色网站| 黄色毛片网站在线观看 | 亚洲精品字幕 | 中文字幕男人的天堂 | 欧美黑人一级爽快片淫片高清 |