473,804 Members | 2,986 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Consecutive requests with XMLHttpRequest under IE

Hi,

I wrote a class to handle requests from the client-side. In particular,
I use :

fuction myClass() {
// ...
this.xhr_object = new ActiveXObject(" Microsoft.XMLHT TP");
// ...
}

In the first implementation of this class, I only instantiated
this.xhr_object (as shown above) once, when a "myClass" object was
created. But then, it happened that I couldn't perform more than one
request with this object : from the second request, the function
onreadystatecha nge would never be called (I made many tests to be sure
of that).

So I changed my class and now I create a new object (with
this.xhr_object = new ActiveXObject(" Microsoft.XMLHT TP");) every time a
request is made. And it works.

So my question is :
Is this behavior normal or have I miss something ?

(In fact, my class is a wrapper for IE and Firefox and under Firefox
this problem doesn't exist : Once you have your HTMLHttpRequest object,
you can make as many requests as you want.)
Thank you all for your (future) answers !

Jul 23 '05 #1
4 2282


Robloche wrote:

I wrote a class to handle requests from the client-side. In particular,
I use :

fuction myClass() {
// ...
this.xhr_object = new ActiveXObject(" Microsoft.XMLHT TP");
// ...
}

In the first implementation of this class, I only instantiated
this.xhr_object (as shown above) once, when a "myClass" object was
created. But then, it happened that I couldn't perform more than one
request with this object : from the second request, the function
onreadystatecha nge would never be called (I made many tests to be sure
of that).


No problem here with IE 6 and the following:

var httpRequest = new ActiveXObject(' Microsoft.XMLHT TP');

for (var i = 0; i < 2; i++) {
httpRequest.ope n('GET', location.href, true);
httpRequest.onr eadystatechange = function () {
if (httpRequest.re adyState == 4) {
alert(httpReque st.responseText );
};
};
httpRequest.sen d(null);
}

the alert shows up twice.

I suspect you set the onreadystatecha nge handler only once but do
several open/send calls then, I think that is a problem with older
versions of MSXML. So it shouldn't be necessary to create a new object
each time you want to make a request but to ensure that after each open
call the onreadystatecha nge handler is set.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
First of all, thank you very much for your answer.
I tried your little piece of code and, of course, it worked.
But as soon as I put it in a class, the bug occurs. Here's my code :

function CreateXMLHTTPRe questObject() {
this.xhr_object = new ActiveXObject(" Microsoft.XMLHT TP");

this.doRequest = function(url) {
//this.xhr_object = new ActiveXObject(" Microsoft.XMLHT TP");

var obj = this;
this.xhr_object .onreadystatech ange = function() {
alert("onreadys tatechange\nrea dyState :
"+obj.xhr_objec t.readyState);
if(obj.xhr_obje ct.readyState == 4)
alert(obj.xhr_o bject.responseT ext);
}

this.xhr_object .open('GET', url, true);
this.xhr_object .send(null);
}
}

var req = new CreateXMLHTTPRe questObject();
req.doRequest(l ocation.href);
req.doRequest(l ocation.href);

As it is, only the first request succeeds. In the second one, the first
alert in the onreadystatecha nge function never shows up...

But if I uncomment the first line of the function doRequest(url), then
the two requests succeed and all the alerts show up.
What's wrong with my class ?

Jul 23 '05 #3


Robloche wrote:

But as soon as I put it in a class, the bug occurs. Here's my code :

function CreateXMLHTTPRe questObject() {
this.xhr_object = new ActiveXObject(" Microsoft.XMLHT TP");

this.doRequest = function(url) {
//this.xhr_object = new ActiveXObject(" Microsoft.XMLHT TP");

var obj = this;
this.xhr_object .onreadystatech ange = function() {
alert("onreadys tatechange\nrea dyState :
"+obj.xhr_objec t.readyState);
if(obj.xhr_obje ct.readyState == 4)
alert(obj.xhr_o bject.responseT ext);
}

this.xhr_object .open('GET', url, true);
this.xhr_object .send(null);


I would change the order as follows (first open(), then setting
onreadystatecha nge, then send()):

this.xhr_object .open('GET', url, true);

var obj = this;
this.xhr_object .onreadystatech ange = function() {
alert("onreadys tatechange\nrea dyState : "+obj.xhr_objec t.readyState);
if(obj.xhr_obje ct.readyState == 4)
alert(obj.xhr_o bject.responseT ext);
}

this.xhr_object .send(null);
Then it works here for me with IE 6 for both requests.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #4
Thank you !!!
It was so simple... I feel kind of dumb... :o/

But why does it work only once when the onreadystatecha nge is set
before opening ?
I went through many web pages that deal with this and I found either
this order or the other one.
Anyway, you saved me hours of debugging, so thanks again !

Jul 23 '05 #5

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

Similar topics

2
1360
by: Christopher Benson-Manica | last post by:
Is there a more crossbrowser-friendly means to make HTTP requests using script than the XML methods? I need to do this in IE 5.0, and it doesn't seem to have the ActiveX control that can make XML HTTP requests. I hope the answer will not be to roll my own HTTP protocol handler :) -- Christopher Benson-Manica | I *should* know what I'm talking about - if I ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
1
4688
by: Mario Figueiredo | last post by:
Hello everyone, I'm having trouble controlling the cursor position when I make two consecutive calls to the get family of functions. This problem does not happen if there is an output in between. The following code illustrates the problem in a simplified way: #include "curses.h"
2
3847
by: dmagliola | last post by:
Hello all, I'm experiencing a problem with ASP.Net for which I can't find a reasonable explanation, or any information. I'm currently developing an application that, through AJAX, asks the server for updated information to show, and can also send information to the server. To do this, I have an XMLHttpRequest that queries an Asynchronous HTTP
1
4036
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest technology is implemented on more sites now than ever. Compatibility is no longer an issue (IE, Mozilla and Opera all support it), and the benefits to using it are amazing. There are too many PHP programmers avoiding any
3
2614
rizwan6feb
by: rizwan6feb | last post by:
Hi experts! Recently i was working on "Form Validation Using Ajax". My form validation was creating problem, when a user changes focus too quickly. I had a post related to this, but was unable to solve the problem. Here is the previous post http://bytes.com/forum/thread798289.html Trying to trace the problem I have written a code (Separate from The Form Validation) which sends 300 requests with an interval of 10 miliseconds and displays the...
7
5454
by: Brent | last post by:
I'm trying to figure out how to iterate over an array that would send a series of XMLHttp requests. I'd like to have each request finish before the next one begins, but I believe that this is not possible to do in a straightforward fashion, given the normally asynchronous method of XMLHttp. The (untested, pseudo) code below gives a little idea of what the goal is, but I'm not really sure how to program it elegantly. One thought I had is...
1
2022
by: bizt | last post by:
Hi, I am having my first real attempt at an ajax class as so far Ive managed to build one that, once instatiated, will allow me to define which function it will call on completion then retrieves the contents from a server side script as AJAX generally does and process it using that function. This far Im quite pleased with it, however, I really want something that will allow me to perform multiple AJAX calls from the same script. I...
2
4132
by: bizt | last post by:
Hi, I have a page that makes many XmlHttpRequest requests from a single page. This works fine but I need some requests to be made over a secure connection. To my understanding, when setting the location of the path to the file to fetch during the XmlHttpRequest request it has to the be the path relative to the web page such as /secret.php and NOT a full URL such as https://www.example.com/secret.php .. is this about the general idea??...
2
2352
by: MedIt | last post by:
Hi All, I am trying to Post a number of requests to a web service on a client server from a console application.Through this application I am firing some 400 requests to the Web Service, one after another. Now the problem, the first few requests gets to the web service, and fails all the consecutive requests after that, returning 404 page not found from IIS, not from the Web Service. We had some problem with the proxy setting from our side,...
0
9706
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10578
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10332
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9152
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.