AngularJS在IE下取數(shù)據(jù)總是緩存問題的解決方法
本文實例講述了AngularJS在IE下取數(shù)據(jù)總是緩存問題解決方法。分享給大家供大家參考,具體如下:
問題:
在使用AngularJS發(fā)出請求(GET)獲取服務(wù)端數(shù)據(jù),然后再綁定到頁面中,你會發(fā)現(xiàn)在IE中總是顯示原來的數(shù)據(jù)結(jié)果。這時候我們就會知道,IE做了緩存。
解決辦法:
我們可以在AngularJS的配置中通過$httpProvider來設(shè)置其不緩存。具體如下所示:
ngApp.config(function ($httpProvider) { // Initialize get if not there if (!$httpProvider.defaults.headers.get) { $httpProvider.defaults.headers.get = {}; } // Enables Request.IsAjaxRequest() in ASP.NET MVC $httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest'; //禁用IE對ajax的緩存 $httpProvider.defaults.headers.get['Cache-Control'] = 'no-cache'; $httpProvider.defaults.headers.get['Pragma'] = 'no-cache'; });
希望本文所述對大家AngularJS程序設(shè)計有所幫助。
相關(guān)文章
AngularJS監(jiān)聽ng-repeat渲染完成的方法
這篇文章主要介紹了AngularJS監(jiān)聽ng-repeat渲染完成的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-03-03AngularJS中$apply方法和$watch方法用法總結(jié)
這篇文章主要介紹了AngularJS中$apply方法和$watch方法用法,結(jié)合實例形式總結(jié)分析了$apply方法和$watch方法的功能、參數(shù)含義、使用技巧與相關(guān)注意事項,需要的朋友可以參考下2016-12-12Angularjs實現(xiàn)mvvm式的選項卡示例代碼
每位Web開發(fā)者應(yīng)該都知道,選項卡是現(xiàn)代web網(wǎng)頁中最常用的效果之一,所以本文重點是用angularjs這個非?;餸vvm框架,實現(xiàn)選項卡效果。有需要的朋友們可以參考借鑒,下面來一起看看吧。2016-09-09