Help with ASP and AJAX

Any help topics that don't fit in the current categories can go here.
Post Reply
wrichards8
Posts: 66
Joined: Thu Jan 12, 2012 3:54 pm
Contact:

Help with ASP and AJAX

Post by wrichards8 »

Hi all,

I'm working on this autocomplete script using AJAX in conjunction with Classic ASP which is not my idea. I have the following javascript:
function showCustomer(str)
{
// remove white space from the name entered on the search screen
str = str.replace(" ", "");
var xmlhttp;    
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="No records found";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  
  
  
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","get_customer.asp?q="+str,true);
xmlhttp.send();
}
My ASP code is as follows:
<%
 response.expires=-1
 dim name
 name = request.querystring("q")


 sql="SELECT person.id, person.forename, person.surname, person.postid, person.extension, person.internal_extension, person.mobile,  person.room_number, job.id, job.postname FROM staff INNER JOIN posts ON job.id = person.postid WHERE (person.forename & person.surname like '%" & name & "%') or job.postname like '%" & name & "%'"
 
 

 
 set conn=Server.CreateObject("ADODB.Connection")
 conn.Provider="Microsoft.Jet.OLEDB.4.0"
 conn.Open("C:\dirplus\database.mdb")
 set rs=Server.CreateObject("ADODB.recordset")
 rs.Open sql,conn

 

 
 response.write("<table>")
 response.write("<thead>")
 response.write("<tr>")
 response.write("<th>Forename</th>")
 response.write("<th>Surname</th>")
 response.write("<th>Extension</th>")
 response.write("<th>Internal Ext.</th>")
 response.write("<th>Mobile</th>")
 response.write("<th>Room No.</th>")
 response.write("<th></th>")
 response.write("</tr>")
 response.write("</thead>")
 response.write("<tbody>")
 Do While Not rs.EOF
 response.write("<tr>")
	 response.write("<td>" & rs("forename") & "</td>")
	 response.write("<td>" & rs("surname") & "</td>")
	 response.write("<td>" & rs("extension") & "</td>")
	 response.write("<td>" & rs("internal_extension") & "</td>")
	 response.write("<td>" & rs("mobile") & "</td>")
	 response.write("<td>" & rs("room_number") & "</td>")
	 response.write("<td>" & rs("post_id") & "</td>")
	 response.write("<td>" & rs("postname") & "</td>")
 response.write("<td><a href='index.asp?View=StaffRecord&StaffID=" & rs("id") & "'>Record</a></td>")
response.write("</tr>")
   rs.MoveNext
 loop
response.write("</tbody>")
response.write("</table>")
 %>
Problem I'm having is that it doesn't work. When I just use a standard form to return the results (via POST or GET) it works fine and when I am just returning the results from the one table it works, but it doesn;t seem to be returning any results with this query
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Help with ASP and AJAX

Post by jacek »

I'm not a huge expert in ASP but if you're just getting no results and not an error then it's probably something to do with the request.

I'd start by checking the value of the str variable in JavaScript and the name variable in ASP.

Also some general JavaScript debugging advice; the console tab in developer tools (F12) will show any script errors.
Image
Post Reply