Jump to content

Ajax problems...


clonetrooper9494

Recommended Posts

I am using AJAX to make a 'live chat', but when I tried to just make a simple AJAX page, it doesn't work. I even copied it off of the w3 website. http://clone-drone.net/axaj_test2.html

<html><body><script language="JavaScript"><!--function SymError(){  return true;}window.onerror = SymError;function SymInitWinOpen(){  if (SymRealWinOpen == null)	 SymRealWinOpen = window.open;  return SymWinOpen;}function SymWinOpen(url, name, attributes){  return (new Object());}var SymRealWinOpen;window.open = SymInitWinOpen();//--></script><script type="text/javascript">function ajaxFunction(){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()	{	if(xmlHttp.readyState==4)	  {	  document.myForm.time.value=xmlHttp.responseText;	  }	}  xmlHttp.open("GET","http://clone-drone.net/time.php",true);//my host doesn't support ASP... so I used PHP  xmlHttp.send(null);  }</script><form name="myForm">Name: <input type="text"onkeyup="ajaxFunction();" name="username" />Time: <input type="text" name="time" /></form></body></html><script language="JavaScript"><!--var SymRealOnLoad;var SymRealOnUnload;function SymOnUnload(){  window.open = SymWinOpen;  if(SymRealOnUnload != null)	 SymRealOnUnload();}function SymOnLoad(){  if(SymRealOnLoad != null)	 SymRealOnLoad();  window.open = SymRealWinOpen;  if (SymRealOnUnload == null)  {	 SymRealOnUnload = window.onunload;	 window.onunload = SymOnUnload;  }}function SymInitWinOnload(){  if ( SymRealOnLoad == null )	 SymRealOnLoad = window.onload;   return SymOnLoad;}window.onload = SymInitWinOnload();//--></script>

http://clone-drone.net/time.php

<?phpecho "testing";?>

No errors, or anything. Can any one see the problem? I tried it in IE, and in FF... and nothing.EDIT:Well thats strange! If you go to http://www.clone-drone.net/axaj_test2.htmlit doesn't work, but tryhttp://clone-drone.net/axaj_test2.htmland it works fine!any one know why the www. affected the ajax code?

Link to comment
Share on other sites

I've never experimented in quite this way, but it seems to be responding to your EXACT url:xmlHttp.open("GET","http://clone-drone.net/time.php",true);maybe x.open() does not supply the missing "www" we get so lazy with. Try rewriting the open() call with the www specified. I bet you get the opposite response.

Link to comment
Share on other sites

I find it normal.Because lots of times a webhost provides subdomains to different customers. They might not want customers to access other customers' accounts or even their main website with AJAX. Javascript always has cross-domain security.Best to use relative URLs with AJAX.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...