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: -
var xmlReqs = new Array();
-
function CXMLHttp(cb,data,xmlHttp)
-
{
-
this.cb = cb;
-
this.data = data;
-
this.xmlhttp = xmlHttp;
-
}
-
-
function ajaxConnect(page,cb,data)
-
{
-
var xmlHttp;
-
-
try
-
{
-
// Firefox, Opera 8.0+, Safari
-
xmlHttp=new XMLHttpRequest();
-
}
-
catch (e)
-
{
-
// Internet Explorer
-
try
-
{
-
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
-
}
-
catch (e)
-
{
-
try
-
{
-
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
-
}
-
catch (e)
-
{
-
alert("Your browser does not support AJAX!");
-
return false;
-
}
-
}
-
}
-
xmlHttp.onreadystatechange=function()
-
{
-
for (var i=0; i < xmlReqs.length; i++)
-
{
-
if (xmlReqs[i].xmlhttp.readyState == 4)
-
{
-
alert('got ' + xmlReqs[i].xmlhttp.responseText);
-
xmlReqs[i].cb(xmlReqs[i].data, xmlReqs[i].xmlhttp.responseText);
-
xmlReqs.splice(i, 1); i--;
-
}
-
}
-
}
-
var i = xmlReqs.push(new CXMLHttp(cb,data,xmlHttp));
-
i--;
-
xmlReqs[i].xmlhttp.open("GET", page, true);
-
xmlReqs[i].xmlhttp.send(null);
-
}
-
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?
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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 >...
|
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. ...
|
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) {
|
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
|
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.
| |
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
|
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
|
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
|
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...
|
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...
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
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();...
| |
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...
| |