473,386 Members | 1,820 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

XMLHttpRequest IE vs FireFox

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[i] = new Option(x[i][1], x[i][0]);
}
}
}

Jun 1 '07 #1
1 5905
shankwheat wrote:
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
Unless an IE 7 user has scripting of ActiveX objects disabled your code
will never end up here with IE 7. Thus if you want your code to use
XMLHttpRequest with IE 7 you should check
if (typeof XMLHttpRequest != 'undefined') {
objXMLHttp = new XMLHttpRequest();
}
first, then if that fails you should use the new ActiveXObject code.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 2 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Chris Smith | last post by:
This is a bit of a weird problem. Unfortunately, I can't reproduce it in a simple example, so I can only poke it out there and see if anyone has seen something similar. I have a script that...
9
by: David | last post by:
Hello I'm testing the XMLHttpRequest object in Firefox and IE. The code below works well in IE and Firefox. It shows "1" when the string is a number and "0" when not. The page aspxTest.aspx only...
3
by: Sergey Surkov | last post by:
Hello Does anybody know how to make FireFox to cache data that comes via XMLHttpRequest? Here is the issue I deal with: - On the web server (apache2) I have a static xml file test.xml - When I...
2
by: petermichaux | last post by:
Hi, I thought it is about time I tried writing some JavaScript with XMLHttpRequest instead of just using the Yahoo! UI library. The simple page below works in both Safari and Opera but I don't...
13
by: TLaufenberg | last post by:
I'm new to Javascript programming and I've run into a bit of a snag with making an XMLHttpRequest in the Safari browser. Actually, the request doesn't work in Firefox either but only when I use a...
5
by: Peter Michaux | last post by:
Hi, The FAQ correctly says the following: "Mozilla (NN6.2+, Firefox, Ice Weasle etc), Opera 7.6+, Safari1.2+, the Windows version of IE versions 5+, and some other browsers provide the XML...
1
by: Charlie | last post by:
I am trying to make an XMLHttpRequest which violates the default "same- origin"policy in Firefox. I checked the archives and found a method that should work but it does not. Below is the test code...
5
by: HugeBob | last post by:
Hi All, I've got a question about Asynchronous vs Synchronous mode with the XMLHttpRequest object. What are the ramifications of using one mode vs the other? If the script uses Asynchronous...
1
by: Iain Adams | last post by:
My code is as follows. http_request = false; if (window.XMLHttpRequest) { alert("firefox"); http_request = new XMLHttpRequest(); } // IE else if (window.ActiveXObject) { alert("ie");
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.