I am reading a xml using $.ajax() request.
$.ajax({
type: "GET",
async: false,
url: "../../../ErrorMessages.xml",
dataType: "xml",
success: function (xml) {
$(xml).find("*[Name='" + Field + "']").each(function () {
message = $(this).find(Rule).text();
});
}
});
I want to make the call only when, the resource ErrorMessages.xml is updated. else use the browser cache.
make a global var named "updateTimeStamp" and put the updatetimestamp into the xml. then find the timestamp when you do the ajax request and compare it to your saved ipdateTimeStamp. if it is bigger then do what you need to do and if not do nothing
Look here: http://jquery14.com/day-01/jquery-14
Etag support was enabled in jQ 1.4, so you could use it.
The browser won't know if
ErrorMessages.xml
has been updated on the server. It has to issue a request to check if the file has been modified.You may want to set the
ifModified
option totrue
in your jQuery$.ajax()
request, since this is set tofalse
by default:Quoting from the jQuery.ajax() documentation:
As long as your web server supports the
Last-Modified
header, then the first request to the XML would look something like this:However, subsequent requests to the same resource will look like this:
If the web server finds that the file has been modified since the
If-Modified-Since
header date, it will serve the file normally.