問題描述
我正在嘗試在我的 Web 應(yīng)用程序中調(diào)試一些棘手的行為:看起來好像客戶端正在發(fā)送 XHR GET 請求,但服務(wù)器實際上從未接收到它.此外,客戶端似乎在看不見的請求中接收到與它發(fā)送的前一個 XHR 請求一樣的重復(fù)數(shù)據(jù).
I'm trying to debug some tricky behaviour in my web application: It appears as though an XHR GET request is being sent by the client, but the server never actually receives it. Furthermore, the client seems to receive duplicate data in the unseen request as the previous XHR request it sends.
更令人困惑的是,F(xiàn)irebug 在 Net 面板中將第二個 XHR 請求著色為淺灰色(這里的請求是倒數(shù)第三個,第二個GET 測試"):
Further confounding matters, Firebug colors the second XHR request as light gray in the Net panel (the request here is third from the bottom, the second "GET test"):
我還沒有找到任何關(guān)于這種顏色含義的文檔.我想如果我理解這一點,它可能有助于解釋這種不尋常的行為.
I haven't been able to find any documentation about what this coloring means. I think if I understood this, it might help explain this unusual behaviour.
如果有人有任何見解,如果你能告訴我,我將不勝感激.
If anyone has any insight, I'd appreciate if you could let me know.
推薦答案
"從緩存中提供的 Firebug 顏色代碼請求淺灰色……"
所以服務(wù)器看不到請求的原因是客戶端從未真正發(fā)送它,它只是從其緩存中接收響應(yīng).如果您使用的是 jQuery,則可以在 ajax() 上使用 cache 屬性防止 AJAX 請求被緩存.如果您不使用 jQuery,您可以在請求 URL 的末尾附加一個虛擬參數(shù),該參數(shù)的值是當(dāng)前時間(以毫秒為單位)(這實際上是 jQuery 所相信的).
So the reason the server doesn't see the request is that the client never actually sends it, it simply receives the response from its cache. If you're using jQuery, there is a cache property that you can use on ajax() to prevent AJAX requests from being cached. If you're not using jQuery you can append a dummy parameter to the end of the request URL that has a value of the current time in milliseconds (this is in fact what jQuery does I believe).
url + "?v=" + (new Date()).getMilliseconds()
這應(yīng)該確保 URL 始終是唯一的,并防止瀏覽器使用緩存.
This should ensure the URL is always unique and prevent the browser from using caching.
這篇關(guān)于如何解釋 Firebug Net 面板中的灰色項目?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!