首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

AJAX相关有关问题提问

2012-09-05 
AJAX相关问题提问ajax.js// JavaScript Documentfunction createxmlhttp(){xmlhttpobj falsetry{xmlhtt

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">单&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;位:</td>
  <td>&nbsp;</td>
  <td height="30">
  <%unit_sql="select * from wy_units"
set unit_rs=user_conn.execute(unit_sql)


tempid=unit_rs("id")%>
  <select name="menu" onChange="getsubcategory(this.value);"> 
<%if not unit_rs.eof then 
do while not unit_rs.eof%>
  <option value="<%=unit_rs("id")%>" ><%=unit_rs("units")%></option>
  <%unit_rs.movenext
loop
end if%>
  </select> <span class="left_ts">*</span></td>
  </tr>
  <tr>
  <td height="30" align="right" bgcolor="#f2f2f2" class="left_txt2">姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名:</td>
  <td bgcolor="#f2f2f2">&nbsp;</td>
  <td height="30" bgcolor="#f2f2f2"><div id="subclass"><select name="submenu"> 
<%name_sql="select * from wy_user where unit="&tempid
set name_rs=user_conn.execute(name_sql)
if not name_rs.eof then 
do while not name_rs.eof%>
  <option value="<%=name_rs("E_N")%>"><%=name_rs("user_name")%></option> 
  <%name_rs.movenext
loop
else
response.Write("<option value='0' selected>暂无小类</option>")
end if%></select>
  <span class="left_ts">*</span></div></td>
  </tr></table>

数据库设计:

wy_units

id int
units nvarchar(255)
Top_id int

wy_user

id int
E_N int
Pic nvarchar(255)
Job nvarchar(255)
user_user nvarchar(255)
user_pass nvarchar(32)
user_name nvarchar(255)
unit int

为什么永远只显示对不起,您请求的页面有问题...

[解决办法]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>海南房地产信息网</TITLE>
<META content="MSHTML 5.00.3315.2870" name=GENERATOR>
<META content=海南房地产信息网 name=Author>
<meta name="keywords" content="海南房地产信息网,海南房地产信息,房地产,海南房地产,海南房地产信,房地产信息,地产信息">
<META content=海南房地产信息网 name=Description>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>

<script type="text/javascript">
var xmlHttp

function showCustomer(str)

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("您的浏览器不支持AJAX!");
return;

var url="time.asp";
url=url+"?q="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function stateChanged()

if (xmlHttp.readyState==4)

document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
</script>


<body>

用户名称: <input size=30 name=username onblur="showCustomer(this.value)"/>
<p>
<div id="txtHint"><b>客户信息将在此处列出。</b></div>
</p>


</body>
</html>

----------------------
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>

<%'---------------------------读写数据库-------------------------------

Response.ContentType = "text/html"
Response.Charset = "GB2312" '解决乱码问题
dim conn
dim connstr
dim db,pass_word,User_ID,Data_Source

db="cw09031" '数据库名称
Pass_word="" 'Password=帐号密码
User_ID="" 'User ID=登陆帐号
Data_Source="" 'Data Source=服务名称或者ip 
Set conn = Server.CreateObject("ADODB.Connection")
connStr="Provider=SQLOLEDB.1;Password='"&pass_word&"';Persist Security Info=True;User 

ID='"&User_ID&"';Initial Catalog='"&db&"';Data Source='"&Data_Source&"'" 
conn.Open connstr
sql="select * from user_info WHERE username ='"&request.querystring("q")&"'"
set rs=conn.execute(sql)
if not rs.eof then
response.write"ok"
else
response.write"对不起,没有这个用户"
end if

Conn.close
Set conn = Nothing
'-----------------------------读写数据库----------------------------
%>

热点排行