Jump to content

Onclick Ajax function wont work more than once?


sw0o0sh

Recommended Posts

I have an onclick that needs to repeat the function as many times as the user may decide to click. However, for some reason no matter what, if they click it once its only going to return the desired effect once, at which point they'd need to re open the page and click it again.

 

Since I don't want to post the whole server side process, I have an example..

 

Here's "TCG.PHP", the page the AJAX communicates with.

 

<?PHP echo rand(0,255); ?>

 

Everytime they click a certain button, it calls the AJAX which calls that page. However, more than one click won't work. Say I push the button, it will return say (39?), and if i click again it just keeps 39 rather than redoing the server side process.

 

And ofcourse, the AJAX

 

function user(input){
var ajaxRequest;
try{
	ajaxRequest = new XMLHttpRequest();
} catch (e){
	try{
		ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try{
			ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e){
			alert("Your browser broke!");
			return false;
		}
	}
}




ajaxRequest.onreadystatechange = function(){
	if(ajaxRequest.readyState == 4){
		   var ajaxDisplay = document.getElementById('u1');
		   ajaxDisplay.innerHTML = ajaxRequest.responseText;
                }
}

   var queryString = "?user=" + input;
   ajaxRequest.open("GET", "tcg.php" + queryString, true);
   ajaxRequest.send(null); 

}

 

And also, the button in which they click:

 

<input type='button' onclick='user("blabla")' />

 

 

Does anyone know what the issue is? >_>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.