AJAX Database ???


AJAX ????????????????????????


AJAX ????????

???????????????????????? AJAX ??????????????? ???????????????????????????????

???


???????????????...

??????? ?


??????? - showCustomer() ????

??????????????????????????????????????????? "showCustomer()" ??????????????? "onchange" ?????????

function showCustomer(str) { var xmlhttp; if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) { // IE7+, Firefox, Chrome, Opera, Safari ????????????? xmlhttp=new XMLHttpRequest(); } else { // 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","/try/ajax/getcustomer.php?q="+str,true); xmlhttp.send(); }

showCustomer() ?????????????????

  • ??????????????????
  • ???? XMLHttpRequest ????
  • ??????????????????????????????
  • ???????????????????????
  • ??????????? URL ????????????? q ?????????????????????

AJAX ?????????

???????? JavaScript ??????????????? PHP ???????? "getcustomer.php"??

?? PHP ?????????????????????????????????????????????? PHP ?????????????????

"getcustomer.php" ???????????????????????????????? HTML ???????????

<%
response.expires=-1
sql="SELECT * FROM CUSTOMERS WHERE CUSTOMERID="
sql=sql & "'" & request.querystring("q") & "'"

set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))
set rs=Server.CreateObject("ADODB.recordset")
rs.Open sql,conn

response.write("<table>")
do until rs.EOF
  for each x in rs.Fields
    response.write("<tr><td><b>" & x.name & "</b></td>")
    response.write("<td>" & x.value & "</td></tr>")
  next
  rs.MoveNext
loop
response.write("</table>")
%>