Web Design Forum: trying to get ajax to work but giving a incorrect repsonse - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

trying to get ajax to work but giving a incorrect repsonse

#1 User is offline   webbhost 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 192
  • Joined: 12-May 08
  • Reputation: 0
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 14 January 2012 - 05:11 PM

Hi all,

Trying to get to grips to ajax... I have written a script to check the response of a php page... as of the minute the php page simply returns "0", However it seems that no matter what the content of the php page (LiveAssistanceHandle.php), the result always comes back as "1".

Can anyone point out my mistake here?


	function init(){
		var xmlhttp;
		if (window.XMLHttpRequest)
		  {// code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		  }
		else
		  {// code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		  }


			xmlhttp.onreadystatechange=function()
			  {
			  if (xmlhttp.readyState==4 && xmlhttp.status==200)
			    {
				    var response = xmlhttp.responseText;
					if (response == "1"){
						alert ("Picked Up - " + response);
					}else{
						alert ("Not Picked Up - " + response);
					}	
			    }
			  }
		xmlhttp.open("GET","LiveAssistanceHandle.php",true);
		xmlhttp.send();			


	}


	window.onload = init;

0

#2 User is offline   webbhost 

  • Dedicated Member
  • PipPip
  • Group: Members
  • Posts: 192
  • Joined: 12-May 08
  • Reputation: 0
  • Experience:Intermediate
  • Area of Expertise:Designer/Coder

Posted 14 January 2012 - 05:37 PM

no worries, I found the problem.... This happens every time I go to use ajax and I always forget so for anyone else that reads this with the same problem...

Once the page has been requested once, my browser seems to be cacheing it.. so if it requests the same page again, rather than contacting the server, it just uses the same response as last time.

I fixed this using this...


xmlhttp.open("GET","LiveAssistanceHandle.php?refresh=" + (new Date().getTime()),true);


Anyone happen to know why this always happens, is there a known fix around it other than the one I just posted?
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users