M14
M14

Reputation: 271

Force browser to reload "cached server side html file data through javascript"

I have an login.dxview file

    <div id="divLoginNews">
        <div data-bind="html:newsContent" style="color:white;"></div>
    </div>

Above div block shows news.html file content. news.html file is at server side. below javascript code reads news.html

$.ajax({
    url: oClientInfo.sRootAddress + '/Information/news.html',
    error: function () {
    },
    success: function (data) {
        viewModel.newsContent(data);
    }
});

issue is if I update the news.html content on page reload, the content is not updated in browser. I understand that in above url, if I get the file modified date as url query string, it should solve issue. I want to syntax for the same. I could not find it till now. (I want to re-load file from server, only when it was changed.)

Upvotes: 0

Views: 359

Answers (1)

Jonel Zape
Jonel Zape

Reputation: 42

You can add parameter like current time on the URL to avoid caching

var today = new Date();
var time = today.getHours() + today.getMinutes() + today.getSeconds();

$.ajax({
    url: oClientInfo.sRootAddress + '/Information/news.html?time=' + time,
    error: function () {
    },
    success: function (data) {
        viewModel.newsContent(data);
    }
});

Upvotes: 1

Related Questions