Jump to content

First Ajax Tutorial Example Problems


K_Drive
 Share

Recommended Posts

I am trying to reproduce the Ajax tutorial example using the time.asp page.I am running it using FireFox 3.0.8. because I get an error using IE ("access denied")I read somewhere that IE doesn't like the HTTPRequest thing and there are security issues when you run it locally. But, that is not my main concern.I am getting the whole text of this asp page in the second text box on the HTML page when I enter something in the first.Here is what I am getting in one long line:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml"> <head> </head> <body> <% response.expires=-1 response.write(time) %> </body> </html>Here is my code for both pages:First, the HTML page with the JavaScript function:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml"><head> <title>AJAX The Server-Side Script</title><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", "time.asp", true);	xmlHttp.send(null);  }</script> </head><body><form name="myForm">Name: <input type="text" onkeyup="ajaxFunction();" name="username" />Time: <input type="text" name="time" /></form></body></html>

And, here is the asp file:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml"><head></head><body><%response.expires=-1response.write(time)%></body></html>

Link to comment
Share on other sites

That's because your ASP page has more text than it needs. You've set it up like a complete document. Doctype, html tags, head tags, body tags. YOU DO NOT NEED THAT STUFF. The tutorial didn't leave it out because they assumed you'd put it back. They left it out because it's supposed to be left out. All you need is the ASP script by itself.

Edited by Deirdre's Dad
Link to comment
Share on other sites

Even so, it looks like your server is returning the ASP code:<% response.expires=-1 response.write(time) %> So it's not actually running the code. Make sure you're testing this on an IIS server with ASP enabled, and make sure you're accessing the page using http. You can't just drag it into the browser or double-click on it, you have to use the http URL in order for ASP to run.

Link to comment
Share on other sites

Thanks, JustSomeGuy.I opened up the Windows Features under Control Panel and ASP wasn't checked.I can run it now. I'm working on an ASP.Net app right now and I was sure that this checkbox was checked. Guess I was wrong.I appreciate your help.K

Edited by K_Drive
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...