четвъртък, 4 февруари 2010 г.

Calling server side script without XMLHttpRequest .

Before few months I was participate in one discussion in one development forum here about calling server side script for "ancient browsers". I mean IE5.5 and others. I isolate getScript function from jQuery and made this outside function. Hope help someone.
/********************************************************************
* This function assumes url of server side
* script as a agrument and execute it asynchronous
* @author: Georgi Naumov
* @param: string scriptUrl url of server side script.
********************************************************************/
function _executeScript(scriptUrl)
{
var done = false;
var head = document.getElementsByTagName("head")[0] || document.documentElement;
var script = document.createElement("script");
var d= new Date();
var re = /\.[a-z]{2,4}\/?$/;
// prevent cashing ..
var last = re.test(scriptUrl) ? "?" : "&";
scriptUrl = scriptUrl + last + "d=" + d.getTime();
script.src = scriptUrl;
script.onload = script.onreadystatechange = function()
{
if ( !done && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete"))
{
done = true;
// Handle memory leak in IE
script.onload = script.onreadystatechange = null;
if ( head && script.parentNode )
{
head.removeChild( script );
}
// here you can do something ..
alert('executed: '+scriptUrl);
}
};
head.insertBefore( script, head.firstChild );
script = null;
}

Няма коментари:

Публикуване на коментар