Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-24-2012, 03:23 PM   PM User | #1
Rrezarta
New to the CF scene

 
Join Date: Sep 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Rrezarta is an unknown quantity at this point
Question Calling multiple Ajax Functions overides response

Hello, I am new to ajax but need to solve a what seems to me a tricky situation.

I receive some live soccer matches data through some xml files that are put in a server. One of the attributes of the xml items is "status" which when a match is currently playing displays the minutes. I build a grid with div-s while reading the xml, and in some particular div I call the function that triggers the ajax, which should return the result to the div which called it.

The php code:
Code:
<div class="status" id="<?php echo $match_id ?>">
                    	<script type="text/javascript"> getStatus('<?php echo $match_id ?>'); </script> 
                    </div>
The Javascript code:
Code:
<script language="javascript" type="text/javascript">
	xmlhttp = new XMLHttpRequest();
	function getStatus(id)
	{	
		xmlhttp.onreadystatechange = 
		function()
		{
			if(xmlhttp.readyState == 4 && xmlhttp.status == 200)
			{ document.getElementById(id).innerHTML = xmlhttp.responseText;
			} else 
			{ document.getElementById(id).innerHTML = "...";
			}
		}
        xmlhttp.open("GET", "functions/returnStatus.php?match_id="+id, true);
		xmlhttp.send();
	}

</script>
For some reason (that i don't know) The ajax returns "..." to all divs except the last one, where it returns the proper result.
Please help, at least with any idea where to start searching for solutions.
Thanks in advance!
Rrezarta is offline   Reply With Quote
Old 09-24-2012, 07:56 PM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
You are using the same XMLHttpRequest object for all the elements. So (except for the last element) there will be only one call for onreadystatechange for each element. Only the last element will reach the readyState==4
devnull69 is offline   Reply With Quote
Reply

Bookmarks

Tags
ajax, multiple, override, requests

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:34 PM.


Advertisement
Log in to turn off these ads.