我好不容易写了一个ASP代码,竟然读不出数据啊~~~大家帮帮忙啊~~郁闷死鸟~~

Dadimamiilove 2009-10-09 06:17:02

<script language="javascript">
httpobj=getHTTPObject();

function getdeptxml()
{
if(httpobj)
{
httpobj.open("POST","departmentinfo.asp",true);
httpobj.onreadystatechange=gotResult;
httpobj.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=gb2312');
httpobj.send(null);
}
}
function gotResult()
{
if (httpobj.readyState==4)
{
if(httpobj.status==200)
{
var xmldoc=new ActiveXObject("Microsoft.XMLDOM");
xmldoc.async=false;
xmldoc.loadXML(httpobj.responseText);
cleartable(dept_table);
var i,tr,td;
i=0;
while(xmldoc.documentElemet.childNodes.item(i)!=null)
{
tr=dept_table.insertRow();
td=tr.insertCell();
td.innerHTML=xmldoc.documentElement.childNodes.item(i).childNodes.item(0).text;
td=tr.insertCell();
td.innerHTML="<input name=cell"+i+"1 type=text value="+unescape(xmldoc.documentElement.childNodes.item(i).chidNodes.item(1).text)+">";
td=tr.insertCell();
td.innerHTML="<input name=cell"+i+"2 type=text value="+unescape(xmldoc.documentElement.childNodes.item(i).chidNodes.item(2).text)+">";
td=tr.insertCell();
td.innerHTML="<input type=button value=修改 onclick=editdept("+i+","+(xmldoc.documentElement.childNodes.item(i).nodeName).substr(3)+")>";
td=tr.insertCell();
td.innerHTML="<input type=button value=删除 onclick=deletedept("+(xmldoc.documentElement.childNodes.item(i).nodeName).substr(3)+")>";
i=i+1;
}
}
}
}

function cleartable(obj)
{
for(var k=obj.rows.length-1;k>=1;k--)
obj.deleteRow(k);
}

function editdept(i,id)
{
if(document.getElementById("cell"+i+"1").value=="")
{
alert("部门名称不能为空");
return;
}
if(httpobj)
{
httpobj.open("POST","edit_department_do.asp",true);
httpobj.onreadystatechange=gotResult_edit;
httpobj.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=gb2312');
param="id="+id+"&deptname="+escape(document.getElementById("cell"+i+"1").value)+"&remark="+escape(document.getElementById("cell"+i+"2").value);
httpobj.send(param);
}
}
function gotResult_edit()
{
if(httpobj.readyState==4)
{
if(httpobj.status==200)
{
if(httpobj.responseText=="success")
window.alert("数据修改成功");
else if(httpobj.responseText=="failed")
window.alert("部门名称发生重复");
}
}
}
function deletedept(id)
{
if(httpobj)
{
httpobj.open("POST","del_department_do.asp",true);
httpobj.onreadystatechange=gotResult_del;
httpobj.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=gb2312');
param="id="+id;
httpobj.send(param);
}
}
function gotResult_del()
{
if(httpobj.readyState==4)
{
if(httpobj.status==200)
{
if(httpobj.responseText=="success")
{
window.alert("数据删除成功");
getdeptxml();
}
else
window.alert("数据删除失败");
}
}
}

function getHTTPObject()
{
var xmlhttp=false;
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
if(xmlhttp.overrideMimeType)
{
xmlhttp.overrideMimeType('text/xml');
}
}
else
{
try
{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(E)
{
xmlhttp=false;
}
}
}
return xmlhttp;
}

</script>

<table id="dept_table" width="100%" border="1" cellspacing="0" cellpadding="0" bordercolorlight="#000000" bordercolordark="#FFFFFF">
<tr>
<td width="70" align="center" class="borderon2">序号</td>
<td width="355" align="center" class="borderon2">部门名称</td>
<td width="308" align="center" class="borderon2">描述</td>
<td width="91" align="center" class="borderon2">修改</td>
<td width="84" align="center" class="borderon2">删除</td>
</tr>
</table>

...全文
175 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
Dadimamiilove 2009-10-10
  • 打赏
  • 举报
回复
hookee大哥~~~我调试成功啦~~~~太感谢你拉~~~~~~~~~~
Dadimamiilove 2009-10-10
  • 打赏
  • 举报
回复
hookee大哥~~现在调试后删除按钮能用了~~但修改的按钮还是没反应的~~~
这是修改后台的代码~~

<!--#include file="conn.asp"-->
<%
id=request("id")
deptname=replace(unescape(request("deptname")),"'","''")
ifexists(deptname)
remark=replace(unescape(request("remark")),"'","''")
sql="update department set deptname='"&deptname&"',remark='"remark"' where id="&id
conn.execute(sql)
response.Write "success"
sub ifexists(dept)
set tmp=server.CreateObject("adodb.recordest")
tmp.open "select deptname from department where deptname='"&dept&"' and id<>"&id,conn
if not tmp.eof then
response.Write "failed"
response.end
end if
end sub
%>
hookee 2009-10-10
  • 打赏
  • 举报
回复
先要单独调试 ajax的页面,否则页面出错的话,没有效果的
Dadimamiilove 2009-10-10
  • 打赏
  • 举报
回复
谢谢hookee大哥~~诶~~但现在~~上面的修改啊删除的按键全不能用鸟~~按什么都没反应啊!~~
hookee 2009-10-10
  • 打赏
  • 举报
回复
工具 - 选项 -Internet选项 - 安全里,把http://localhost/ 加入本地站点-站点-高级-添加
然后选本地站点 - 自定义级别 - 把选项中的ActiveX相关项启用 看看

Dadimamiilove 2009-10-10
  • 打赏
  • 举报
回复
全部启用鸟~~但是还是不行啊~~~~~hookeed大哥!!
hookee 2009-10-10
  • 打赏
  • 举报
回复
浏览器不允许使用XMLDOM,在菜单-工具-管理项加载中启用MSXML相关组件 就可以了
Dadimamiilove 2009-10-10
  • 打赏
  • 举报
回复
网页错误详细信息
消息: Automation 服务器不能创建对象
行: 20
字符: 4
代码: 0
URI: http://localhost/实验/index2.asp

hookee大哥!!这是什么意思啊??没见过的??()
hookee 2009-10-10
  • 打赏
  • 举报
回复
都是一些拼写错误, 改了gotResult(), 加了window.onload

单独访问departmentinfo.asp,确保 返回的xml格式正确,就可以得到数据了.


<script language="javascript">
httpobj=getHTTPObject();

function getdeptxml()
{
if(httpobj)
{
httpobj.open("GET","departmentinfo.asp",true);
httpobj.onreadystatechange=gotResult;
httpobj.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=gb2312');
httpobj.send(null);
}
}
function gotResult()
{
if (httpobj.readyState==4)
{
if(httpobj.status==200)
{
var xmldoc=new ActiveXObject("Microsoft.XMLDOM");
xmldoc.async=false;alert(httpobj.responseText)
xmldoc.loadXML(httpobj.responseText);
cleartable(dept_table);
var i,tr,td;
i=0;
while(xmldoc.documentElement.childNodes.item(i)!=null)
{
tr=dept_table.insertRow();
td=tr.insertCell();
td.innerHTML=xmldoc.documentElement.childNodes.item(i).childNodes.item(0).text;
td=tr.insertCell();
td.innerHTML="<input name=cell"+i+"1 type=text value="+unescape(xmldoc.documentElement.childNodes.item(i).childNodes.item(1).text)+">";
td=tr.insertCell();
td.innerHTML="<input name=cell"+i+"2 type=text value="+unescape(xmldoc.documentElement.childNodes.item(i).childNodes.item(2).text)+">";
td=tr.insertCell();
td.innerHTML="<input type=button value=修改 onclick=editdept("+i+","+(xmldoc.documentElement.childNodes.item(i).nodeName).substr(3)+")>";
td=tr.insertCell();
td.innerHTML="<input type=button value=删除 onclick=deletedept("+(xmldoc.documentElement.childNodes.item(i).nodeName).substr(3)+")>";
i=i+1;
}
}
}
}

function cleartable(obj)
{
for(var k=obj.rows.length-1;k>=1;k--)
obj.deleteRow(k);
}

function editdept(i,id)
{
if(document.getElementById("cell"+i+"1").value=="")
{
alert("部门名称不能为空");
return;
}
if(httpobj)
{
httpobj.open("POST","edit_department_do.asp",true);
httpobj.onreadystatechange=gotResult_edit;
httpobj.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=gb2312');
param="id="+id+"&deptname="+escape(document.getElementById("cell"+i+"1").value)+"&remark="+escape(document.getElementById("cell"+i+"2").value);
httpobj.send(param);
}
}
function gotResult_edit()
{
if(httpobj.readyState==4)
{
if(httpobj.status==200)
{
if(httpobj.responseText=="success")
window.alert("数据修改成功");
else if(httpobj.responseText=="failed")
window.alert("部门名称发生重复");
}
}
}
function deletedept(id)
{
if(httpobj)
{
httpobj.open("POST","del_department_do.asp",true);
httpobj.onreadystatechange=gotResult_del;
httpobj.setRequestHeader('Content-Type','application/x-www-form-urlencoded;charset=gb2312');
param="id="+id;
httpobj.send(param);
}
}
function gotResult_del()
{
if(httpobj.readyState==4)
{
if(httpobj.status==200)
{
if(httpobj.responseText=="success")
{
window.alert("数据删除成功");
getdeptxml();
}
else
window.alert("数据删除失败");
}
}
}

function getHTTPObject()
{
var xmlhttp=false;
if(window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
if(xmlhttp.overrideMimeType)
{
xmlhttp.overrideMimeType('text/xml');
}
}
else
{
try
{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(E)
{
xmlhttp=false;
}
}
}
return xmlhttp;
}
window.onload=function(){
getdeptxml()
}

</script>

<table id="dept_table" width="100%" border="1" cellspacing="0" cellpadding="0" bordercolorlight="#000000" bordercolordark="#FFFFFF">
<tr>
<td width="70" align="center" class="borderon2">序号</td>
<td width="355" align="center" class="borderon2">部门名称</td>
<td width="308" align="center" class="borderon2">描述</td>
<td width="91" align="center" class="borderon2">修改</td>
<td width="84" align="center" class="borderon2">删除</td>
</tr>
</table>
Dadimamiilove 2009-10-10
  • 打赏
  • 举报
回复
啊~~~帮帮忙吧大家~~~
Dadimamiilove 2009-10-09
  • 打赏
  • 举报
回复

<!--#include file="conn.asp"-->
<?xml version="1.0" encoding="gb2312"?>
<datalist>
<%
set rs=server.CreateObject("adodb.recordset")
sql="select * from department"
rs.open sql,conn
i=1
while not rs.eof
response.Write "<rec"&rs("id")&">"
response.Write "<r0>"&i&"</r0>"
response.Write "<r1>"&escape(rs("deptname"))&"</r1>"
response.Write "<r2>"&escape(rs("remark"))&"</r2>"
response.Write "</rec"&rs("id")&">"
rs.movenext
i=i+1
wend
%>
</datalist>

这是xml代码部分~~~

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧