久久久久久久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>
                          主站蜘蛛池模板: 亚洲国产一区视频 | 亚洲成年人免费网站 | 精品欧美乱码久久久久久 | 99这里只有精品视频 | 亚洲一级毛片 | 91麻豆精品国产91久久久更新资源速度超快 | 久草精品视频 | 久草网址 | 久久网一区二区 | 国产精品久久久一区二区三区 | 欧美精品v国产精品v日韩精品 | 成人在线观看网站 | 欧美精品在线一区 | 一区二区三区国产视频 | 99免费在线观看 | 国产成人精品一区二区 | 91porn国产成人福利 | 亚洲综合视频 | 一区二区三区四区在线播放 | 国产在线播 | 亚洲福利一区 | 亚洲欧美aⅴ| 久久久亚洲一区 | 精品久久久久久久久久久院品网 | 精品毛片| 欧美日韩电影一区 | 国产在线a | 中文字幕日韩欧美 | 日本小电影网站 | 自拍偷拍中文字幕 | 亚洲精品一区中文字幕乱码 | 久色激情 | 国产三区av | 黄片毛片免费观看 | 国产成人精品a视频一区www | 9191在线观看 | 日本精品999 | 日韩精品在线播放 | 99精品欧美一区二区三区综合在线 | 精品国产91乱码一区二区三区 | 一区视频|