NameSilo

More than one ajax request?

Spaceship Spaceship
Watch

omegapandor

Established Member
Impact
4
I'm just learning about the XmlHttpRequest object. I have a basic demonstration for myself built, but I can only use it once. After pressing the "submit" button, I have to exit out of firefox before trying it again. If I press the button more than once, nothing happens.

I think I need to restart the object for accepting requests at the end of my code or something. . .but I don't know how.

Pls. . .helps. . .

Code:
createobjectandstuff()
{

req.onreadystatechange = function()
		{ 
			document.ajax.txt.value="Attacking...";
			if(req.readyState == 4)
			{
				if(req.status == 200)
				{
					document.ajax.txt.value=req.responseText;	
				}	
				else	
				{
					document.ajax.txt.value="Error: returned status code " + req.status + " " + req.statusText;
				}	
			} 
		}; 
		req.open("GET", "fileiwantoget.php", true); 
		req.send(null);
	}
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
i'm no ajax expert, but whenever i've used it i've always called the function with onkeyup, onchange, onblur, or onfocus.

if you look on w3schools.com they have the basic framework that almost all ajax scripts need (which i don't see in your code, but then again you could be doing some other method i don't know about).
 
0
•••
I just realized that my submit button creates the object every time. I assume this is bad and has something to do with the problem.
 
0
•••

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back