[jQuery] ajax with ifmodified - handling of null in last modified
In my current application I was working with jquery ajax api with
ifmodified enabled. This was working great for me and I was using 304s
to my heart's content. In a particular case, the server side
application was returning a Http code 200 but was not setting the Last-
Modified header. Because of this, in firefox I found that jquery
instead of taking it as a 200 as it is, it was treating it as a 304
and returning an error code of "notmodified". The returned
XMLHttpRequest was ignored. When I debugged using firebug, I found
that the problem. The method "httpNotModified" in jQuery does the
following:
1 httpNotModified: function( xml, url ) {
2 try {
3 var xmlRes = xml.getResponseHeader("Last-Modified");
4
5 // Firefox always returns 200. check Last-Modified date
6 return xml.status == 304 || xmlRes == jQuery.lastModified[url] ||
7 jQuery.browser.safari && xml.status == undefined;
8 } catch(e){}
9 return false;
10 }
In line 3, the method is retrieving the Last-Modified header. Since
the server has not set it, the value is coming out as null.
In line 6, there is a comparison between xmlRes (value is null) and
jQuery.lastModified (value is undefined), and this comparison turns
out to be equal. This causes jQuery to decide that the status of the
call is "notmodified" and hence it returns a notmodified error and
ignores the server response.
I tried adding a null check inside this method (and converting the
null to an empty string) and then everything works fine.
This is something we might want to do within the jquery library
itself. Please let me know your thoughts.
Thanks,
nacnez