win8: 確保 WinJS.xhr 重新發送請求

來源:互聯網
上載者:User

在做一個擷取sina 公用微博的小小demo,在最後重新整理時發現用winjs.xhr調用很快就會返回資料,但是返回的資料都是第一次的資料。這是因為load 的是同樣的url,在訪問web時會有cache,導致無法Reload。

check:http://msdn.microsoft.com/en-us/library/windows/apps/hh868281.aspx

 

通過使用 WinJS.xhr 請求 Web 資源時,可能會緩衝響應,這意味著之後的請求將返回用戶端計算上已存在的資源版本,而不是重新發送請求。但是,可以添加確保即使已經緩衝也會再次發送請求的 HTTP 標題。

設定 If-Modified-Since HTTP 標題,該標題指定用戶端應該重新發送請求以檢查是否存在較新版本的資源。向 WinJS.xhr 函數添加 options 參數的 headers 屬性的 If-Modified-Since 標題。有關 HTTP 響應標題的詳細資料,請參閱 HTTP Response Headers

WinJS.xhr({     url: "http://www.microsoft.com",    headers: {        "If-Modified-Since": "Mon, 27 Mar 1972 00:00:00 GMT"    } })    .done(function complete(result) {        // Report download.        xhrDiv.innerText = "Downloaded the page";        xhrDiv.style.backgroundColor = "#00FF00";});

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.