Copy Code code as follows:
<%
Response. Expires=-1
Response. Cachecontrol= "No-cache"
%>
<!--#include file= ". /.. /conn/conn.asp "-->
<!--#include file= ". /psw.asp "-->
<!--#include file= ". /.. /functions/dofunction.asp "-->
<!--#include file= ". /.. /functions/showfunction.asp "-->
<!--#include file= ". /.. /fqdb/admin/website.asp "-->
<%
cmd = checkstr (Request ("cmd"), 2)
If cmd= "Loadteacher" Then
Response. Charset = "gb2312"
Set Rs=server. CreateObject ("Adodb.recordset")
Sql= "Select Teacher_id,name from Edu_person"
Rs.Open sql,conn,1,3
Response.Write "{" "Data" ": ["
i = 0
Do Until rs.eof
i = i + 1
Response.Write "{" "Id" ":" &rs ("teacher_id") & "," "Name" ":" "&rs (" name ") &" "}"
If I<rs.recordcount then Response.Write ","
Rs.movenext ()
Loop
Response.Write "]}"
Response. End ()
End If
%>
Copy Code code as follows:
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title> Untitled Document </title>
<script type= "Text/javascript" src= ". /.. /js/common/jquery-1.8.0.min.js "></script>
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ ("#btn1"). Click (function () {
Alert ("click");
$.ajax ({
URL: "Ajaxtest.asp?cmd=loadteacher",
DataType: "JSON",
Success:function (JSON) {
var OData = $.parsejson (JSON);
var data = Json.data;
for (var i = 0,len = Data.length;i<len; i++) {
Document.writeln (Data[i]. Name);
}
}
});
});
});
</script>
<body>
<form id= "MyForm" method= "post" action= "ajaxtest.asp" >
<!--<input type= "hidden" name= "cmd" value= "Loadteacher" >-->
<select id= "tearchers" name= "Teachers" >
<option value= "Please choose" ></option>
</select>
<input type= "button" id= "Btn1" name= "btn1" value= "Load Teacher" >
<!--<input type= "Submit" value= "submitted" >-->
</form>
</body>