<script language="JavaScript"> <!-- //在后台读取记录集生成的XML function cseChange(oRid) { var oXMLDoc = new ActiveXObject('MSXML'); sURL = "couseList.asp?CouseId=" +oRid.value; oXMLDoc.URL = sURL; var oRoot=oXMLDoc.root; var coll = document.all.tags("input"); if (coll!=null) var i=0; for (var j=0;j<coll.length;j++) { if(coll[j].type=="text") { if(coll[j].name.substr(0,7)=="txtYear") { if(oRoot.children != null) { for(i;i<=oRoot.children.length;++i) { oItem= oRoot.children.item("subject",0); if(coll[j].name.substr(0,7)=="txtYear") { coll[j].value=oItem.children.item(i).text; j++; } } } } } } }
--> </script>
couseList.asp代码 ------------------------------ <?xml version="1.0" encoding="gb2312" ?> <% intCouseId=request.querystring("CouseId") if intCouseId<>"" then dim Conn,Rs,strSQL,connstr dim dbUser,dbPwd,dbDsn If Request.Cookies("dblink").Haskeys then dbUser=Request.Cookies("dblink")("dbUser") dbPwd=Request.Cookies("dblink")("dbPwd") dbDsn=Request.Cookies("dblink")("dbDsn") else dbUser="dlmis" dbPwd="dlmis" dbDsn="Oracle" end if
connstr="Provider=MSDAORA.1;Password="&dbPwd&";User ID="&dbUser&";Data Source="&dbDsn&";Persist Security Info=True" set conn=server.createobject("ADODB.CONNECTION") conn.open connstr set rs=server.createobject("adodb.recordset") strSQL="select stime,etime from tbl_class where classid="&intCouseId Rs.Open strSQL,Conn,3,1 end if %> <subjects> <% do while not Rs.eof %> <subject> <couseName><%=formatdatetime(Rs("stime"),1)%></couseName> <classId><%=formatdatetime(Rs("etime"),1)%></classId> </subject> <% Rs.movenext loop %> </subjects> ---------------------------------------------------------------
agree icer
然后在web页面,隔段时间就用javascript读服务器上的XML
function initTable(nRow,nCell)
{
var htmlstr="<TABLE id=t1 cellSpacing=1 cellPadding=1 width=100% ><TBODY>";
htmlstr=htmlstr+"<tr width=100%>";
for (j=0;j<nCell;j++)
{
htmlstr=htmlstr+"<td></td>";
}
htmlstr=htmlstr+"</tr>"
for ( i=0;i<nRow;i++)
{
htmlstr=htmlstr+"<tr>";
for (j=0;j<nCell;j++)
{
htmlstr=htmlstr+"<td></td>";
}
htmlstr=htmlstr+"</tr>";
}
htmlstr=htmlstr+"</TBODY></TABLE>";
layer1.innerHTML =htmlstr;
}
这样来添加数据。。不过事先都将Xml的数据读到数组里了nRow,nCell有数组的维数得到。。function AddItem()
{
for (j=0;j<numCell;j++)
{
document.all.t1.tBodies[0].rows[0].cells[j].innerHTML="<font color='white'>"+menuTitle[j]+"</font>";
}
for (i=0;i<numRow;i++)
{
for (j=0;j<numCell;j++)
{
if (i<tmpnumRow)
{
document.all.t1.tBodies[0].rows[i+1].cells[j].innerHTML=tmptabledata[i][j];
}
}
}
}<div id="layer1" class="p1" style="OVERFLOW:auto;HEIGHT:170px"></div>
XmlHttp.open("POST", "你的WebService地址", false);
XmlHttp.Send()
xmlDoc = new ActiveXObject('Microsoft.XMLDOM')
xmlDoc.async = false;
xmlDoc.load(XmlHttp.responseXML)然后分析xmlDoc。。
这是我以前写的一个页面调到例子,Web Service返回的是一个DataSet
你可以参考一下
在服务器端
public void SetWebService()
{
//设定WEB服务器
string usl="http://"+this.Request.ServerVariables["SERVER_NAME"].ToString()+this.ResolveUrl("GetMessage.asmx")+"?WSDL";
this.Response.Write("<script>");
this.Response.Write("function init(){");
this.Response.Write("myWebService.useService(\""+usl+"\",\"service1\");");
this.Response.Write("Getd();");
this.Response.Write("}");
this.Response.Write("</script>");
}
public void SetTable()
{
//输出显示数据的表格
this.Response.Write("<TABLE id='Table1' style='Z-INDEX: 101; LEFT: 0px; WIDTH: 100%; POSITION: absolute; TOP: 0px; HEIGHT:400px; BACKGROUND-COLOR: #e7e7ff' cellSpacing='1' cellPadding='1' width='668' bgColor='#e7e7ff' border='0'>");
this.Response.Write("<TR bgColor='#6371d6'>");
this.Response.Write("<TD style='WIDTH: 30px; HEIGHT: 20px;FONT-WEIGHT: bold; COLOR: white; ' align='middle'><FONT face='宋体'>编号</FONT></TD>");
this.Response.Write("<TD style='WIDTH: 100px; HEIGHT: 20px;FONT-WEIGHT: bold; COLOR: white; ' align='middle'><FONT face='宋体'>时间</FONT></TD>");
this.Response.Write("<TD style='WIDTH: 136px; HEIGHT: 20px;FONT-WEIGHT: bold; COLOR: white; ' align='middle'><FONT face='宋体'>事件</FONT></TD>");
this.Response.Write("<TD style='WIDTH: 114px; HEIGHT: 20px;FONT-WEIGHT: bold; COLOR: white; ' align='middle'><FONT face='宋体'>员工</FONT></TD>");
this.Response.Write("<TD style='WIDTH: 74px; HEIGHT: 20px;FONT-WEIGHT: bold; COLOR: white; ' align='middle'><FONT face='宋体'>卡号</FONT></TD>");
this.Response.Write("<TD style='WIDTH: 70px; HEIGHT: 20px;FONT-WEIGHT: bold; COLOR: white; ' align='middle'><FONT face='宋体'>地点</FONT></TD>");
this.Response.Write("<TD style='WIDTH:30px;HEIGHT: 20px;FONT-WEIGHT: bold; COLOR: white; ' align='middle'><FONT face='宋体'>查看</FONT></TD>");
this.Response.Write("<TD style='WIDTH: 1px; HEIGHT: 20px;display:none' align='middle'><FONT face='宋体'></FONT></TD>");
this.Response.Write("<TD style='WIDTH: 1px; HEIGHT: 20px;display:none' align='middle'><FONT face='宋体'></FONT></TD>");
this.Response.Write("<TD style='WIDTH:1px;HEIGHT: 20px;display:none' align='middle'><FONT face='宋体'></FONT></TD>");
this.Response.Write("<TD style='WIDTH:1px;HEIGHT: 20px;display:none' align='middle'><FONT face='宋体'></FONT></TD>");
this.Response.Write("</TR>");
for(int i=1;i<=25;i++)
{
this.Response.Write("<TR id='tr"+i+"' bgColor='#e7e7ff'>");
this.Response.Write("<TD onmouseover='if(document.all[\"idno"+i.ToString()+"\"].value!=\"\") highlight(tr"+i+",\"LightSeaGreen\");' onclick='ListEmployee("+i+");' style=\"WIDTH: 30px; HEIGHT: 18px\" onmouseout='highlight(tr"+i+",\"e7e7ff\")' align='middle'><INPUT class=\"ednonedisable\" id='idno"+i+"'style=\"WIDTH: 30px; HEIGHT: 13px\" type=\"text\" size=\"3\" readOnly></TD>");
this.Response.Write("<TD onmouseover='if(document.all[\"idno"+i.ToString()+"\"].value!=\"\") highlight(tr"+i+",\"LightSeaGreen\");' onclick='ListEmployee("+i+");' style=\"WIDTH: 100px; HEIGHT: 18px\" onmouseout='highlight(tr"+i+",\"e7e7ff\")' align='middle'><FONT face=\"宋体\"><INPUT class=\"ednonedisable\" id='eventdate"+i+"' style=\"WIDTH: 100px; HEIGHT: 14px\" type=\"text\" size=\"9\" readOnly></FONT></TD>");
this.Response.Write("<TD onmouseover='if(document.all[\"idno"+i.ToString()+"\"].value!=\"\") highlight(tr"+i.ToString()+",\"LightSeaGreen\");'onclick='ListEmployee("+i+");' style=\"WIDTH: 136px; HEIGHT: 18px\" onmouseout='highlight(tr"+i.ToString()+",\"e7e7ff\")' align='middle'><INPUT class=\"ednonedisable\" id='eventtype"+i.ToString()+"' style=\"WIDTH: 128px; HEIGHT: 14px\" type=\"text\" size=\"16\" readOnly></TD>");
this.Response.Write("<TD onmouseover='if(document.all[\"idno"+i.ToString()+"\"].value!=\"\") highlight(tr"+i.ToString()+",\"LightSeaGreen\");' onclick='ListEmployee("+i+");' style=\"WIDTH: 114px; HEIGHT: 18px\" onmouseout='highlight(tr"+i.ToString()+",\"e7e7ff\")' align='middle'><INPUT class=\"ednonedisable\" id='employee"+i.ToString()+"' style=\"WIDTH: 117px; HEIGHT: 14px\" type=\"text\" size=\"14\" readOnly></TD>");
this.Response.Write("<TD onmouseover='if(document.all[\"idno"+i.ToString()+"\"].value!=\"\") highlight(tr"+i.ToString()+",\"LightSeaGreen\");'onclick='ListEmployee("+i+");' style='WIDTH: 74px; HEIGHT: 18px' onmouseout='highlight(tr"+i.ToString()+",\"e7e7ff\")' align='middle'><INPUT class='ednonedisable' id='cardno"+i.ToString()+"' style='WIDTH: 82px; HEIGHT: 14px' type='text' size='8' readOnly></TD>");
this.Response.Write("<TD onmouseover='if(document.all[\"idno"+i.ToString()+"\"].value!=\"\") highlight(tr"+i.ToString()+",\"LightSeaGreen\");' onclick='ListEmployee("+i+");' style='WIDTH: 70px; HEIGHT: 18px' onmouseout='highlight(tr"+i.ToString()+",\"e7e7ff\")' align='middle'><FONT face='宋体'><INPUT class='ednonedisable' id='reader"+i.ToString()+"' style='WIDTH: 72px; HEIGHT: 14px' type='text' size='6' readOnly></FONT></TD>");
this.Response.Write("<TD onmouseover='if(document.all[\"idno"+i.ToString()+"\"].value!=\"\") highlight(tr"+i.ToString()+",\"LightSeaGreen\");' onclick='ListEmployee("+i+");' style='HEIGHT: 18px;width=20px' onmouseout='highlight(tr"+i.ToString()+",\"e7e7ff\")' align='middle'><FONT face='宋体'><INPUT type='checkbox' id='chk"+i.ToString()+"'onclick='Reader(document.all[\"idno"+i.ToString()+"\"].value)' style=\"display:none\"></FONT></TD>");
this.Response.Write("<TD onmouseover='if(document.all[\"idno"+i.ToString()+"\"].value!=\"\") highlight(tr"+i.ToString()+",\"LightSeaGreen\");' style=\"WIDTH: 1px; HEIGHT: 18px;display:none\" onmouseout='highlight(tr"+i.ToString()+",\"e7e7ff\")' align='middle'><INPUT class=\"ednonedisable\" id='mjgroup"+i.ToString()+"' style=\"WIDTH: 1px; HEIGHT: 14px\" type=\"text\" size=\"14\"></TD>");
this.Response.Write("<TD onmouseover='if(document.all[\"idno"+i.ToString()+"\"].value!=\"\") highlight(tr"+i.ToString()+",\"LightSeaGreen\");' style='WIDTH: 74px; HEIGHT: 18px;display:none' onmouseout='highlight(tr"+i.ToString()+",\"e7e7ff\")' align='middle'><INPUT class='ednonedisable' id='kqgroup"+i.ToString()+"' style='WIDTH: 1px; HEIGHT: 14px' type='text' size='8'></TD>");
this.Response.Write("<TD onmouseover='if(document.all[\"idno"+i.ToString()+"\"].value!=\"\") highlight(tr"+i.ToString()+",\"LightSeaGreen\");' style='WIDTH: 74px; HEIGHT: 18px;display:none' onmouseout='highlight(tr"+i.ToString()+",\"e7e7ff\")' align='middle'><INPUT class='ednonedisable' id='photoname"+i.ToString()+"' style='WIDTH: 1px; HEIGHT: 14px' type='text' size='8'></TD>");
this.Response.Write("<TD onmouseover='if(document.all[\"idno"+i.ToString()+"\"].value!=\"\") highlight(tr"+i.ToString()+",\"LightSeaGreen\");' style='WIDTH: 74px; HEIGHT: 18px;display:none' onmouseout='highlight(tr"+i.ToString()+",\"e7e7ff\")' align='middle'><INPUT class='ednonedisable' id='department"+i.ToString()+"' style='WIDTH: 1px; HEIGHT: 14px' type='text' size='8'></TD>");
this.Response.Write("</TR>");
}
this.Response.Write("</TABLE>");
}
<HEAD>
<title>刷卡记录</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<LINK href="../css/turbocrm.css" type="text/css" rel="stylesheet">
<script src="../js/Command.js"></script>
<% SetWebService();%>
<script>
function Getd()
{
myWebService.service1.callService(GetData,"GetKq");
window.setTimeout("Getd()",3000);
//window.setInterval("Getd()",2000);
}
function Reader(a)
{
//查看记录
myWebService.service1.callService("ReaderEvent",a);
}
function ClearEvent()
{
//清除记录
myWebService.service1.callService("ClearEvent");
}
function RefreshEvent()
{
//刷新记录
myWebService.service1.callService("RefreshEvent");
}
function ListEmployee(idno)
{
document.all["txtName"].value=document.all["employee"+idno].value;
document.all["txtCardno"].value=document.all["cardno"+idno].value;
document.all["txtMjgroup"].value=document.all["mjgroup"+idno].value;
document.all["txtKqgroup"].value=document.all["kqgroup"+idno].value;
document.all["txtDepartment"].value=document.all["department"+idno].value;
document.all["photo"].src="../webrs/photo/"+document.all["photoname"+idno].value;
}
function GetData(result)
{
var bbXML = new ActiveXObject("Msxml2.DOMDocument");
bbXML.async = false;
var xmlResult =result.raw.xml;
if (xmlResult != "" && xmlResult != null)
{
bbXML.loadXML(xmlResult);
var msg=bbXML.selectSingleNode ("//NewDataSet");
if(msg!=null)
{
var msg1,msg2;
var i=1;
msgid=msg.selectNodes("//Table");
var strDate;
do
{
msg1=bbXML.selectSingleNode ("//NewDataSet").selectNodes("//Table").item(i-1);
//msg2=msg1.text;
document.all["idno"+i].value=msg1.selectNodes ("//idno").item(i-1).text;
strDate=msg1.selectNodes ("//eventdate").item(i-1).text;
document.all["eventdate"+i].value=strDate.toLocaleString();
document.all["eventtype"+i].value=msg1.selectNodes ("//eventtype").item(i-1).text;
document.all["employee"+i].value=msg1.selectNodes ("//employee").item(i-1).text;
document.all["cardno"+i].value=msg1.selectNodes ("//cardno").item(i-1).text;
document.all["reader"+i].value=msg1.selectNodes ("//reader").item(i-1).text;
document.all["kqgroup"+i].value=msg1.selectNodes ("//kqgroup").item(i-1).text;
document.all["mjgroup"+i].value=msg1.selectNodes ("//mjgroup").item(i-1).text;
document.all["photoname"+i].value=msg1.selectNodes ("//photoname").item(i-1).text;
document.all["department"+i].value=msg1.selectNodes ("//department").item(i-1).text;
document.all["chk"+i].style.display="";
if(msg1.selectNodes ("//progress").item(i-1).text=="YES")
{
document.all["chk"+i].checked=true;
document.all["chk"+i].disabled=true;
}
else
{
document.all["chk"+i].checked=false;
document.all["chk"+i].disabled=false;
}
i++;
}while(bbXML.selectSingleNode ("//NewDataSet").selectNodes("//Table").item(i-1)!=null&&i<=25)
for(;i<=25;i++)
{
document.all["idno"+i].value="";
document.all["eventdate"+i].value="";
document.all["eventtype"+i].value="";
document.all["employee"+i].value="";
document.all["cardno"+i].value="";
document.all["reader"+i].value="";
document.all["chk"+i].style.display="none";
document.all["kqgroup"+i].value="";
document.all["mjgroup"+i].value="";
document.all["photoname"+i].value="";
document.all["department"+i].value="";
}
}
else
{
var i;
for(i=1;i<=25;i++)
{
document.all["idno"+i].value="";
document.all["eventdate"+i].value="";
document.all["eventtype"+i].value="";
document.all["employee"+i].value="";
document.all["cardno"+i].value="";
document.all["reader"+i].value="";
document.all["chk"+i].style.display="none";
document.all["kqgroup"+i].value="";
document.all["mjgroup"+i].value="";
document.all["photoname"+i].value="";
document.all["department"+i].value="";
}
}
}
}
</script>
</HEAD>
<body onload="init()" MS_POSITIONING="GridLayout" background="../images/metal_bg01.gif">
<form id="Form1" method="post" runat="server">
<DIV id="myWebService" style="BEHAVIOR: url(webservice.htc)"><FONT face="宋体"></FONT></DIV>
<DIV id="reader" style="BORDER-RIGHT: thin groove; BORDER-TOP: thin groove; Z-INDEX: 101; LEFT: 184px; BORDER-LEFT: thin groove; WIDTH: 588px; BORDER-BOTTOM: thin groove; POSITION: absolute; TOP: 36px; HEIGHT: 534px" ms_positioning="GridLayout">
<% SetTable();%>
</DIV>
webservice如何返回数据?直接返回DATASET类型的数据?还是要在webservice中手工生成一个字串,内容是代表数据库数据的XML结构数据,然后再返回、由客户端分析XML数据?
可以直接返回DataSet
当然它是以XML的形式表式的。
我用你的方法作了个程序,成功了!!
但是好像在IE 5 上不能自动更新数据,是否是因为IE版本的问题?
按echeng192(阿飞)的方法可以实现。
请教 knightufp(try catch finally .) :如何用推的技术?
能否说的在详细些
把服务器端的方法可以直接拿到客户端(javascript)中调用。
它的基本原理是使用MSXML的XMLHTTP来进行数据的传输
<!--
//在后台读取记录集生成的XML
function cseChange(oRid)
{
var oXMLDoc = new ActiveXObject('MSXML');
sURL = "couseList.asp?CouseId=" +oRid.value;
oXMLDoc.URL = sURL;
var oRoot=oXMLDoc.root;
var coll = document.all.tags("input");
if (coll!=null)
var i=0;
for (var j=0;j<coll.length;j++)
{
if(coll[j].type=="text")
{
if(coll[j].name.substr(0,7)=="txtYear")
{
if(oRoot.children != null)
{
for(i;i<=oRoot.children.length;++i)
{
oItem= oRoot.children.item("subject",0);
if(coll[j].name.substr(0,7)=="txtYear")
{
coll[j].value=oItem.children.item(i).text;
j++;
}
}
}
}
}
}
}
-->
</script>
couseList.asp代码
------------------------------
<?xml version="1.0" encoding="gb2312" ?>
<% intCouseId=request.querystring("CouseId")
if intCouseId<>"" then
dim Conn,Rs,strSQL,connstr
dim dbUser,dbPwd,dbDsn
If Request.Cookies("dblink").Haskeys then
dbUser=Request.Cookies("dblink")("dbUser")
dbPwd=Request.Cookies("dblink")("dbPwd")
dbDsn=Request.Cookies("dblink")("dbDsn")
else
dbUser="dlmis"
dbPwd="dlmis"
dbDsn="Oracle"
end if
connstr="Provider=MSDAORA.1;Password="&dbPwd&";User ID="&dbUser&";Data Source="&dbDsn&";Persist Security Info=True"
set conn=server.createobject("ADODB.CONNECTION")
conn.open connstr
set rs=server.createobject("adodb.recordset")
strSQL="select stime,etime from tbl_class where classid="&intCouseId
Rs.Open strSQL,Conn,3,1
end if
%>
<subjects>
<% do while not Rs.eof %>
<subject>
<couseName><%=formatdatetime(Rs("stime"),1)%></couseName>
<classId><%=formatdatetime(Rs("etime"),1)%></classId>
</subject>
<% Rs.movenext
loop %>
</subjects>
---------------------------------------------------------------