AJAX相关问题提问
ajax.js
// JavaScript Document
function createxmlhttp()
{
xmlhttpobj = false;
try{
xmlhttpobj = new XMLHttpRequest;
}catch(e){
try{
xmlhttpobj=new ActiveXObject("MSXML2.XMLHTTP");
}catch(e2){
try{
xmlhttpobj=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e3){
xmlhttpobj = false;
}
}
}
return xmlhttpobj;
}
function getsubcategory(bigclassid){
if(bigclassid==0){
document.getElementById("subclass").innerHTML="<select name='smallclassid'><option value='0' selected>选择二级分类</option></select>";
return;
};
var xmlhttpobj = createxmlhttp();
if(xmlhttpobj){//如果创建对象xmlhttpobj成功
xmlhttpobj.onreadystatechange=handle;
xmlhttpobj.open('get',"../getsubcategory.asp?unit="+bigclassid+"&name="+Math.random(),true);//get方法 加个随机数。
xmlhttpobj.send(null);
}
}
function handle(){//客户端监控函数
//if(xmlhttpobj.readystate==4){//服务器处理请求完成
if(xmlhttpobj.status==200){
//alert('ok');
var html = xmlhttpobj.responseText;//获得返回值
document.getElementById("subclass").innerHTML=html;
}else{
document.getElementById("subclass").innerHTML="对不起,您请求的页面有问题...";
}
//}
//else{
//document.getElementById("subclass").innerHTML=xmlhttpobj.readystate;//服务器处理中
//}
//}
}
getsubcategory.asp
<%@language="vbscript" codepage="936"%>
<!--#include file="../conn.asp"-->
<%
response.charset="gb2312"
unit=request.querystring("unit")
name_id=request.QueryString("name")
if unit<>"" then
set re=new regexp
re.ignorecase=true
re.global=false
re.pattern = "^[0-9]{1,3}$"
if not re.test(unit) then
response.write "非法参数"
response.end
end if%>
<%on error resume next
sql="select * from wy_user where unit="&unit
set p = user_conn.execute(sql)
if err then
err.clear
response.write "查询出错"
response.end
end if
if not p.eof then
html = "<select name='select2'>"&vbnewline
do while not p.eof
html = html&"<option value="&p("E_N")&">"&p("user_name")&"</option>"&vbnewline
p.movenext
loop
html = html&"</select>"
else
html = "<option value='0' selected>暂无小类</option>"
end if
p.close
set p = nothing
conn.close
set conn = nothing
response.write html
end if
%>
用户访问的页面(段)
<script language="javascript" type="text/javascript" src="js/ajax.js"></script>
<table>
<tr>
<td height="30" align="right" class="left_txt2">单 位:</td>
<td> </td>
<td height="30">