AngularJS在IE下取數據總是緩存問題的解決方法
更新時間:2016年08月05日 11:38:11 作者:Quber
這篇文章主要介紹了AngularJS在IE下取數據總是緩存問題的解決方法,分析了問題的原因及AngularJS設置禁止IE對ajax緩存的實現方法,需要的朋友可以參考下
本文實例講述了AngularJS在IE下取數據總是緩存問題解決方法。分享給大家供大家參考,具體如下:
問題:
在使用AngularJS發(fā)出請求(GET)獲取服務端數據,然后再綁定到頁面中,你會發(fā)現在IE中總是顯示原來的數據結果。這時候我們就會知道,IE做了緩存。
解決辦法:
我們可以在AngularJS的配置中通過$httpProvider來設置其不緩存。具體如下所示:
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程序設計有所幫助。
相關文章
AngularJS監(jiān)聽ng-repeat渲染完成的方法
這篇文章主要介紹了AngularJS監(jiān)聽ng-repeat渲染完成的方法,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-03-03AngularJS中$apply方法和$watch方法用法總結
這篇文章主要介紹了AngularJS中$apply方法和$watch方法用法,結合實例形式總結分析了$apply方法和$watch方法的功能、參數含義、使用技巧與相關注意事項,需要的朋友可以參考下2016-12-12