S
shankwheat
I use this code to populate a selectbox with a group of records from a
database. It executes very quickly with FireFox 2.0 but takes 7-10
secs with IE6 and IE7. Just wondering if anyone had any pointers for
improving this code to make IE run it faster or I am just stuck with
it? Thanks
function GetXmlHttpObject()
{
var objXMLHttp=null
try {
objXMLHttp = new ActiveXObject("Msxml2.XMLHTTP"); //later IE
} catch (e) {
try {
objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP"); //earlier IE
} catch (e) {
objXMLHttp = null;
}
}
if (objXMLHttp==null)
{
objXMLHttp=new XMLHttpRequest() //IE7, Firefox, Safari
}
return objXMLHttp
}
function getCompanies()
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Your browser does not support the XMLHttpRequest object.")
return
}
var url="getCompanies.aspx"
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
document.getElementById("lblResults").innerHTML = "<img
src='mozilla_blu.gif' alt='loading..please wait'>"; //loading
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("lblResults").innerHTML = "";
// Clear the available listbox of any previous options
document.choiceForm.available.length = 0;
// Split the delimited response into an array
var s = xmlHttp.responseText;
var re = new RegExp('{([^{}]*)}','g');
var x = [];
while (re.exec(s)){
x.push(RegExp.$1.split('#'));
}
// Add the array options to the selectbox available
var sel = document.forms['choiceForm'].elements['available'];
for (var i=0, len=x.length; i<len; i++){
sel.options = new Option(x[1], x[0]);
}
}
}
database. It executes very quickly with FireFox 2.0 but takes 7-10
secs with IE6 and IE7. Just wondering if anyone had any pointers for
improving this code to make IE run it faster or I am just stuck with
it? Thanks
function GetXmlHttpObject()
{
var objXMLHttp=null
try {
objXMLHttp = new ActiveXObject("Msxml2.XMLHTTP"); //later IE
} catch (e) {
try {
objXMLHttp = new ActiveXObject("Microsoft.XMLHTTP"); //earlier IE
} catch (e) {
objXMLHttp = null;
}
}
if (objXMLHttp==null)
{
objXMLHttp=new XMLHttpRequest() //IE7, Firefox, Safari
}
return objXMLHttp
}
function getCompanies()
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Your browser does not support the XMLHttpRequest object.")
return
}
var url="getCompanies.aspx"
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
document.getElementById("lblResults").innerHTML = "<img
src='mozilla_blu.gif' alt='loading..please wait'>"; //loading
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("lblResults").innerHTML = "";
// Clear the available listbox of any previous options
document.choiceForm.available.length = 0;
// Split the delimited response into an array
var s = xmlHttp.responseText;
var re = new RegExp('{([^{}]*)}','g');
var x = [];
while (re.exec(s)){
x.push(RegExp.$1.split('#'));
}
// Add the array options to the selectbox available
var sel = document.forms['choiceForm'].elements['available'];
for (var i=0, len=x.length; i<len; i++){
sel.options = new Option(x[1], x[0]);
}
}
}