[SUGGESTION] Instead of this...
Code:
function getXMLHttpRequestObject()
{
// Initialize the object:
var req = false;
// Choose object type based upon what's supported:
if (window.XMLHttpRequest)
{
// IE 7, Mozilla, Safari, Firefox, Opera, most browsers:
req = new window.XMLHttpRequest();
}
else if (window.ActiveXObject)
{
// Create type Msxml2.XMLHTTP, if possible:
req = new window.ActiveXObject("Msxml2.XMLHTTP");
}
else
{
req = new window.ActiveXObject("Microsoft.XMLHTTP");
}
return req;
}
... try this:
Code:
function getXMLHttpRequestObject()
{
if(window.XMLHttpRequest) return new window.XMLHttpRequest(); // IE 7, Mozilla, Safari, Firefox, Opera, most browsers
else if(window.ActiveXObject) return new window.ActiveXObject("Msxml2.XMLHTTP"); // Create type Msxml2.XMLHTTP, if possible
else return new window.ActiveXObject("Microsoft.XMLHTTP");
return 0; // return 0 just in case none of the statements apply
}
The second version saves more memory (
). Instead of this...
Code:
function get(url, target)
{
var req = null;
req = getXMLHttpRequestObject();
if(req)
{//alert( startRow );
req.onreadystatechange = function()
{
if(req.readyState == 4)
{
var result = document.getElementById(target);
result.innerHTML = req.responseText;
}
else
{
var loading = document.getElementById(target);
loading.innerHTML = 'loading';
}
}
req.open('get', url, true);
req.send(null);
}
else
{
alert('Request failed.');
}
}
...try this:
Code:
function get(url, target)
{
var req = getXMLHttpRequestObject();
if(req)
{
// alert(startRow);
req.onreadystatechange = function() {
if(req.readyState == 4) document.getElementById(target).innerHTML = req.responseText;
else document.getElementById(target).innerHTML = "loading";
};
req.open("get", url, true);
req.send(null);
}
else alert("Request failed.");
}
I'm not sure if you would need 'req', but I'll include it just in case. Then there's this...
Code:
function getlist()
{
var onLoadActions = new Array();
function addOnLoadAction(action)
{
onLoadActions[onLoadActions] = action;
}
function performOnLoadActions()
{
for (var count =0; count < onLoadActions.length; count++)
{
eval(onLoadActions[count]);
}
}
addOnLoadAction(get('bg.php','content1'));
addOnLoadAction(get('text1.php','content2'));
addOnLoadAction(get('text2.php','content3'));
}
...to this:
Code:
function getlist()
{
var onLoadActions = [];
function addOnLoadAction(action)
{
onLoadActions[onLoadActions] = action;
}
function performOnLoadActions()
{
for (var count = 0; count < onLoadActions.length; count++) eval(onLoadActions[count]);
}
addOnLoadAction(get("bg.php","content1"));
addOnLoadAction(get("text1.php","content2"));
addOnLoadAction(get("text2.php","content3"));
}
[/SUGGESTION]
Bookmarks