Jump to content

AJAX problem


eng.mohamed_elqpany

Recommended Posts

i need your help in learning AJAX. i have a problem in my first example in AJAX. It's supposed to recieve a response from the server side but no response at all (null).this my codehtml file

<html><head><script src="clienthint.js"></script> </head><body><% response.write("fadf") %><form> First Name:<input type="text" id="txt1" name="txt"><input type="button" name="btn1" value="Click" onclick="showHint(txt.value)"></form><p>Suggestions: <span id="txtHint"></span></p>  </body></html>

and this is the java script file

var xmlHttpfunction showHint(str){if (str.length==0){ document.getElementById("txtHint").innerHTML=""return}xmlHttp=GetXmlHttpObject()if (xmlHttp==null){alert ("Browser does not support HTTP Request")return} alert(str)var url="gethint.asp"url=url+"?q="+strurl=url+"&sid="+Math.random()xmlHttp.onreadystatechange=stateChanged xmlHttp.open("POST",url,true)alert("Escap1")xmlHttp.send(null)} function stateChanged() { if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){ document.getElementById("txtHint").innerHTML=xmlHttp.responseText alert(xmlHttp.responseText)} } function GetXmlHttpObject(){ var objXMLHttp=nullif (window.XMLHttpRequest){objXMLHttp=new XMLHttpRequest()}else if (window.ActiveXObject){objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")}return objXMLHttp}

and this is the server side code

<%dim a(30)'Fill up array with namesa(1)="Anna"a(2)="Brittany"a(3)="Cinderella"a(4)="Diana"a(5)="Eva"a(6)="Fiona"a(7)="Gunda"a(8)="Hege"a(9)="Inga"a(10)="Johanna"a(11)="Kitty"a(12)="Linda"a(13)="Nina"a(14)="Ophelia"a(15)="Petunia"a(16)="Amanda"a(17)="Raquel"a(18)="Cindy"a(19)="Doris"a(20)="Eve"a(21)="Evita"a(22)="Sunniva"a(23)="Tove"a(24)="Unni"a(25)="Violet"a(26)="Liza"a(27)="Elizabeth"a(28)="Ellen"a(29)="Wenche"a(30)="Vicky"'get the q parameter from URLq=ucase(request.querystring("q"))'lookup all hints from array if length of q>0if len(q)>0 then  hint=""  for i=1 to 30	if q=ucase(mid(a(i),1,len(q))) then	  if hint="" then		hint=a(i)	  else		hint=hint & " , " & a(i)	  end if	end if  nextend if'Output "no suggestion" if no hint where found'or output the correct valuesif hint="" then   response.write("no suggestion")else  response.write(hint)end if%>

i hope u help me. and i need to know the basics of that technology.and if you can provide an open source code example.thanx..

Link to comment
Share on other sites

Try changing this:xmlHttp.open("POST",url,true)to this:xmlHttp.open("GET",url,true)When requesting data, you should use GET instead of POST.Also, instead of sending the request as null, use the empty string:xmlHttp.send("")And try adding an alert to your callback function to make sure it's even getting executed:

function stateChanged() {   alert("stateChanged called: " + xmlHttp.readyState)  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")  { 	document.getElementById("txtHint").innerHTML=xmlHttp.responseText	alert(xmlHttp.responseText)  } }

Link to comment
Share on other sites

What happens if you just visit your ASP page (gethint.asp) in your browser by typing in the address in the address bar? Do you see "no suggestion"? What happens if you visit "gethint.asp?q=ci", do you see "Cinderella"? Or, when you do these tests, are you only seeing your ASP code?

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
×
×
  • Create New...