PDA

View Full Version : HTML5 offline mode + AJAX = bug



thx51
24 May 2011, 12:47 PM
Hi everybody,

I have a little bug in the Ext.Ajax library. In fact, in HTML5 offline mode we can't execute Ajax request (it fall into error, as if the resource didn't exists).

It's easily reproducible, I have downloaded the Kitchen sink demo (http://dev.sencha.com/deploy/touch/examples/kitchensink/), uploaded it on my server, and configured properly the cache.manifest.

So the site was perfectly working, but there were serveral problems in offline mode. For example we can't change the theme (a loading wheel was endlessly turning). Actually this is due to the ajax request of the css file, which caused an error of loading.

But with a little hack in the "themes.js", I was able to fix this specific problem. I have simply replaced the Ext.Ajax.request by a standard XMLHttpRequest, and it was working :


(function() {
function appendStyleSheet(url, callback) {
var head = document.head || document.getElementsByTagName('head')[0],
firstLink = document.getElementsByTagName('link')[0],
style = document.createElement('style');

style.type = 'text/css';

xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if (xhr.readyState == 4) {
style.textContent = xhr.responseText;
if (firstLink) {
head.insertBefore(style, firstLink);
} else {
head.appendChild(style);
}
callback(style.sheet);
} else {
}
};
xhr.open( "GET", url, true);
xhr.send(null);

/* Ext.Ajax.request({
url: url,
success: function(response) {
style.textContent = response.responseText;

if (firstLink) {
head.insertBefore(style, firstLink);
} else {
head.appendChild(style);
}

callback(style.sheet);
}
});
*/ ....

So I think that Ext.Ajax need a little patch to fix this bug, what do you think ?

elmasse
15 Dec 2011, 11:17 AM
Have you tried to add noCache: false parameter in Ext.Ajax call?