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

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

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

      捕獲 javascript XMLHttpRequest 的重定向位置

      Capture redirect location of javascript XMLHttpRequest(捕獲 javascript XMLHttpRequest 的重定向位置)

        <tbody id='0owX9'></tbody>

        <small id='0owX9'></small><noframes id='0owX9'>

            <legend id='0owX9'><style id='0owX9'><dir id='0owX9'><q id='0owX9'></q></dir></style></legend>

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

              <tfoot id='0owX9'></tfoot>
              • <bdo id='0owX9'></bdo><ul id='0owX9'></ul>
                本文介紹了捕獲 javascript XMLHttpRequest 的重定向位置的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                問題描述

                我知道你不能在使用 XMLHttpRequest 時(shí)攔截或阻止重定向,因?yàn)闉g覽器會(huì)透明地跟隨它,但是有可能

                I know that you can't, when using an XMLHttpRequest, intercept a redirect or prevent it, as the browser will transparently follow it, but is it possible to either

                A.確定請(qǐng)求是否被重定向,或者

                A. Determine whether a request redirected, or

                B.確定它重定向到的哪里?(假設(shè)響應(yīng)沒有給出任何提示)

                B. Determine where it redirected to? (assuming that the response gives no hints)

                示例代碼:

                $.post("/my-url-that-redirects/", {}, 
                    function(response, statusCode, xmlHttpRequest){
                        //Somehow grab the location it redirected to
                    }
                );
                

                在我的例子中,firebug 將首先顯示一個(gè) POST 到 url,然后一個(gè) GET 到重定向的 url.可以捕獲該 GET 位置嗎?

                In my case, firebug will first show a POST to the url, then a GET to the redirected url. Can that GET location be captured?

                推薦答案

                1) 使用不同于 301 (2**) 的狀態(tài)碼(如果通過 ajax 請(qǐng)求)并在客戶端處理重定向:

                1) Use different status code than 301 (2**) (if request by ajax) and handle redirection on client side:

                var STATUS = {
                  REDIRECT: 280
                };
                
                $.post('/redirected', {}, function(response, status, request) {
                  if (status == STATUS.REDIRECT) {
                    // you need to return the redirect url
                    location.href = response.redirectUrl;
                  } else {
                    $('#content').html(request.responseText);
                  }
                });
                

                2) 不要重定向:

                我在重定向模式"中使用它=在發(fā)布請(qǐng)求后重定向(您不想讓用戶刷新發(fā)布請(qǐng)求等)

                I use that in "redirect pattern" = redirecting after post request (you don't want to allow user to refresh the post request, etc..)

                對(duì)于 ajax 請(qǐng)求,這不是必需的,所以當(dāng)發(fā)布請(qǐng)求是 ajax 時(shí),我會(huì)改為轉(zhuǎn)發(fā)(只是轉(zhuǎn)發(fā)到不同的控制器 - 取決于您的服務(wù)器端框架,或者您正在使用什么......).POST 請(qǐng)求不會(huì)被瀏覽器緩存.

                With ajax request, this is not necessary, so when the post request is ajax, I do forward instead (just forward to different controller - depends on your server-side framework, or what you are using...). POST requests are not cached by browsers.

                實(shí)際上,我不知道你需要它的原因是什么,所以這對(duì)你來說可能不是那么有用.這在服務(wù)器返回的 ajax 請(qǐng)求與普通請(qǐng)求不同的響應(yīng)時(shí)很有幫助,因?yàn)楫?dāng)瀏覽器重定向 ajax 請(qǐng)求時(shí),重定向的請(qǐng)求不是 XMLHttpRequest...

                Actually, I don't know what's the reason you need that, so this might not be so useful for you. This is helpful when server returns different responses for ajax requests than common requests, because when browser redirect ajax request, the redirected request is not XMLHttpRequest...

                [更新]

                您可以像這樣訪問(重定向請(qǐng)求的)標(biāo)頭:

                You can access headers (of redirected request) like that:

                $.post('redirected', {}, function(r, s, req) {
                  req.getAllResponseHeaders();
                  req.getResponseHeader('Location');
                });
                

                應(yīng)該有'Location'標(biāo)頭,但這取決于服務(wù)器,哪些標(biāo)頭被發(fā)回......

                There should be 'Location' header, but it depends on the server, which headers are sent back...

                這篇關(guān)于捕獲 javascript XMLHttpRequest 的重定向位置的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                相關(guān)文檔推薦

                Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調(diào)用 abort (jQuery) 之后,瀏覽器也會(huì)等待 ajax 調(diào)用完成)
                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 無法加載,請(qǐng)求的資源上不存在“Access-Control-Allow-Origin標(biāo)頭) - IT屋-程序員軟件開發(fā)技術(shù)分
                Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請(qǐng)求是否有可能不遵循重定向 (301 302))
                NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內(nèi)容)
                  <tbody id='5NojS'></tbody>
              • <tfoot id='5NojS'></tfoot>

                    <legend id='5NojS'><style id='5NojS'><dir id='5NojS'><q id='5NojS'></q></dir></style></legend>

                      <small id='5NojS'></small><noframes id='5NojS'>

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

                          <bdo id='5NojS'></bdo><ul id='5NojS'></ul>
                          主站蜘蛛池模板: 一区二区三区四区免费在线观看 | 国产伦一区二区三区久久 | 欧美国产日韩在线观看 | 91中文字幕在线观看 | 欧美成人免费在线 | 男女羞羞免费网站 | 一区二区三区视频免费看 | 国产成人免费视频网站视频社区 | 国产精品久久久久久久久久免费看 | 成人精品国产 | 97久久超碰 | 日本三级电影免费观看 | 久久精品视频在线观看 | 久久久久久久久久久久久久久久久久久久 | 日韩欧美二区 | 在线观看视频福利 | 51ⅴ精品国产91久久久久久 | 亚洲精选久久 | 国产日屁| 亚洲成人免费网址 | 91在线看| 午夜精品网站 | 日本韩国电影免费观看 | 久久国产亚洲精品 | 亚洲精品久久久久久首妖 | 伊人欧美视频 | 亚洲成年在线 | 亚洲在线一区二区三区 | 365夜爽爽欧美性午夜免费视频 | 国产精品婷婷 | 国产一区视频在线 | 日本一区二区三区在线观看 | 精品一区av| 91精品久久久久久久久 | 日韩av一区二区在线观看 | 欧美一级二级在线观看 | 妖精视频一区二区三区 | 日韩欧美中文在线 | 91精品国产一区二区 | 欧美日韩一区二区在线播放 | 久久久91精品国产一区二区三区 |