473,624 Members | 2,234 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XMLhttp object goes away

1 New Member
Ok, I'm very new to AJAX programming, and fairly new to Javascript. (I was originally trained on low-level C programming.) I'm trying to build a simple AJAX routine in a file named ajax.js:

Expand|Select|Wrap|Line Numbers
  1. var xmlReqs = new Array();
  2. function CXMLHttp(cb,data,xmlHttp)
  3. {
  4.     this.cb = cb;
  5.     this.data = data;
  6.     this.xmlhttp = xmlHttp;
  7. }
  8.  
  9. function ajaxConnect(page,cb,data)
  10. {
  11.     var xmlHttp;
  12.  
  13.     try
  14.     {
  15.         // Firefox, Opera 8.0+, Safari
  16.         xmlHttp=new XMLHttpRequest();
  17.     }
  18.     catch (e)
  19.     {
  20.         // Internet Explorer
  21.         try
  22.         {
  23.             xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  24.         }
  25.         catch (e)
  26.         {
  27.             try
  28.             {
  29.                 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  30.             }
  31.             catch (e)
  32.             {
  33.                 alert("Your browser does not support AJAX!");
  34.                 return false;
  35.             }
  36.         }
  37.     }
  38.     xmlHttp.onreadystatechange=function()
  39.     {
  40.         for (var i=0; i < xmlReqs.length; i++)
  41.         {
  42.             if (xmlReqs[i].xmlhttp.readyState == 4)
  43.             {
  44.                 alert('got ' + xmlReqs[i].xmlhttp.responseText);
  45.                 xmlReqs[i].cb(xmlReqs[i].data, xmlReqs[i].xmlhttp.responseText);
  46.                 xmlReqs.splice(i, 1); i--;
  47.             }
  48.         }
  49.     }
  50.     var i = xmlReqs.push(new CXMLHttp(cb,data,xmlHttp));
  51.     i--;
  52.     xmlReqs[i].xmlhttp.open("GET", page, true);
  53.     xmlReqs[i].xmlhttp.send(null);
  54. }
  55.  
I have an onclick routine that calls this like this:
ajaxConnect('ge t_item.php?ajax =1&item=' + item, onItem, tem);

The trouble is when it hits the alert, another debugging session shows that the xmlhttp property seems to be empty. I've been staring at this for a day now but I don't see the problem. I know I'm doing some newbie error, but I don't yet see it. Any help?
Mar 25 '09 #1
1 1489
gits
5,390 Recognized Expert Moderator Expert
in your onreadystate-handler you loop through a number of request-objects in a callback for every single request ... i think this will cause the behaviour that you encounter ...

kind regards
Mar 27 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
7571
by: Graham Mattingley | last post by:
Hello I had this idea that I thought was going to be really simple, and I just cant get it to work.. I have use an affiliate link on my site, and I did not like it because it did not have my sites banners on it, so I asked the permission of the other site to change the display and they aggreed.. The affiliate site has 4 pages of forms linking to each other so it goes something like form.asp > results.asp > results_details.asp >...
5
6069
by: Justice | last post by:
Currently I'm doing some experimenting with the XMLHTTP object in Javascript. Now, the XMLHttp object is asynchronous (at least in this case), and the following code causes a significant memory loss even though I seem to be allocaitng everything; help would be *vastly* appreciated. What am I doing wrong here? I thought I was doing everything correctly (setting things to null, for example) but none of the memory seems to get replaced. ...
6
3253
by: Krzysztof Kubiak | last post by:
I'm trying to make use of XMLHTTP object, but I've come across a problem. It seems that there is no way to create dynamic array of such XMLHTTP objects (to make several requests) and handle them properly. I was trying to use such code: <script lang="javascript"> function handleOnReadyStateChange() { if (this.readyState==4) {
3
1984
by: kajol | last post by:
Hi everyone I am trying to get the content of any webpage (URL) using XMLHTTP, and it is working fine for me, but suddenly I have got a URL "http://www.bizrate.com/" which is causing a system error and the error is System.Runtime.InteropServices.COMException(0xC00CE56E): System error:- 1072896658
2
2902
by: Jason Morehouse | last post by:
Hello, Anyone know if it's possible to speak with the server via xmlhttp.open while the browser is doing a post -- file upload in this case: <form enctype="multipart/form-data" action="product" method="post" name="product" onSubmit="do_action_form(); return true;"> .... <script> // .. setup xmlhttp here.
12
13786
by: Botan Guner | last post by:
Hi all, Here is the problem, i'm using Microsoft.XMLHTTP for ie and XMLHttpRequest for mozilla, on my local server which is win2000 server i've no problem with that but when i uploaded the file to the web server of our company which is redhat 9 i still have no problem with mozilla but the ie gives an error like this, System error: -1072896658
3
6488
by: Dag Sunde | last post by:
I'm trying to call an ASP script with the XMLHttp object in Client-side Javascript (which goes well). My problem is that the server gives me an error when I try to set a Session variable in the called asp-script: "Type Mismatch: Session". I guess it is because it is the XMLHttp object that is now the client (from the servers point ov view), and that object does not share the session with the client-browser containing the
5
449
by: jim.frantzen | last post by:
You have an active XMLHTTP request on the main page (localhost/App1/index.aspx) The XMLHTTP request takes about 60 seconds to receive a response back from localhost/App1/getxml.aspx. You have an IFRAME on this main page. When you set the iframe's src to google.com, it works fine. When you set the iframe's src to localhost/App1/test.htm, it works fine. When you set the iframe's src to
6
10449
by: Vanessa | last post by:
I have a question regarding async mode for calling Microsoft.XMLHTTP object. Microsoft.XMLHTTP hangs the IE once in a while suddenly, but it will work again after half an hour or so without doing anything. I have searched through the Internet and seems like the reason it hangs the browser it's because XMLHTTP limits you to two concurrent HTTP connections to each remote host; so if more than 2 concurrent connections strike the script...
0
8242
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
8177
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8681
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...
1
8341
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
8488
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7170
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...
1
6112
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
1488
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.