PDA

View Full Version : whats wrong with my first ajax



gencoglu4
08-02-2007, 11:23 PM
hi,
I have just tested my "first ajax" program but suprisingly it did not work for me..
I copied and paste both "testAjax.htm" and "time.asp"
There are two textboxes on the page ...if you write a name in textbox 1 ,the other textbox is supposed to display the current time..but it showed nothing:confused:
What am I missing?


<html><body><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><form name="myForm">
Name: <input type="text"
onkeyup="ajaxFunction();" name="username" />
Time: <input type="text" name="time" />
</form></body>
</html>

-----test.asp--------------------------------
<%
response.expires=-1
response.write(time)
%>

rwedge
08-03-2007, 02:27 AM
Looks like some of the Javascript comments // are blocking some code:
<script type="text/javascript">
/*<![CDATA[*/
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>

gencoglu4
08-03-2007, 08:42 PM
No ..still there is problem..
inside the textbox there is this" response.expires=-1"

rwedge
08-03-2007, 09:50 PM
The ajax is working ok, it returns the data you asp script is giving it.
Check the asp docs to see how to return the time