K_Drive Posted April 1, 2009 Share Posted April 1, 2009 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 More sharing options...
jeffman Posted April 1, 2009 Share Posted April 1, 2009 AJAX would be a pretty worthless technology if you were supposed to send back a complete HTML document. You are not. Print only the data that your javascript requires. Link to comment Share on other sites More sharing options...
K_Drive Posted April 1, 2009 Author Share Posted April 1, 2009 I'm sorry. I wasn't clear enough on this post.Here is what this tutorial example is supposed to do:Link to w3schools Ajax tutorial exampleYou enter something in the first text field, and the time is returned in the second. I am getting the whole text of the asp page and I cannot figure out why. Link to comment Share on other sites More sharing options...
jeffman Posted April 1, 2009 Share Posted April 1, 2009 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. Link to comment Share on other sites More sharing options...
justsomeguy Posted April 1, 2009 Share Posted April 1, 2009 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 More sharing options...
K_Drive Posted April 1, 2009 Author Share Posted April 1, 2009 Like a .js file? Just put in the text with nothing else? OK. I did that. Now, I am getting this returned in the second text field:<% response.expires=-1 response.write(time) %> Link to comment Share on other sites More sharing options...
justsomeguy Posted April 1, 2009 Share Posted April 1, 2009 See my response above. Link to comment Share on other sites More sharing options...
K_Drive Posted April 1, 2009 Author Share Posted April 1, 2009 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 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.