页面:
<#83cript language=javascript id=clientEventHandlersJS type=text/javascript>
function getdata()
{
var index=0;
docSubmit =new ActiveXObject("Microsoft.XMLDOM");
docSubmit.async = false;
docSubmit.load("http://localhost/WebAlication1/Service1.asmx/GetData?maxval=5");
docSubmit.loadXML(docSubmit.xml.replace(/</g,"<").replace(/>/g,">"));
var s="";
nodeList=docSubmit.documentElement.getElementyTagName("ds");
for (i=0;i
';
}
div1.ierHtml ="";
div1.ierHTML=
div1.style.visibility="visible";
}
</Script>
lt;IUT type="button" value="Button" onclick="getdata()">ltr>
ltan id="div1" cla="list">lt;/agt;
ltcript language=javascript>
etInterval(getdata,1000); //动态定时调用
lt;/script>
脚本:
ltCRIPT ID="clientEventHandlersJS" LANGUAGE="javascript">
function getdata()
#123;
var index=0
docSubmit =new ActiveXObject("Microsoft.XMLDOM");
docSubmit.async = false
docSubmit.load("http://localhost/WebAlication1/Service1.asmx/GetData?maxval=5");'>http://localhost/WebAlication1/Service1.asmx/GetData?maxval=5")
docSubmit.loadXML(docSubmit.xml.replace(/&amlt;/g,"<").replace(/&amgt;/g,">"));
var s=""
odeList=docSubmit.documentElement.getElementyTagName("ds");
for (i=0;i<odeList.length;i++)
#123;
=s+nodeList(i).selectSingleNode("KeShimch").text+'<r>';
#125;
div1.ierHtml ="";
div1.ierHTML=
div1.style.visibility="visible"
#125
lt;/script>
//如果返回是个字符串:
ltCRIPT ID="clientEventHandlersJS" LANGUAGE="javascript">
function chang()
#123
docSubmit =new ActiveXObject("Microsoft.XMLDOM");
docSubmit.async = false
docSubmit.load("http://localhost/Advertisement/ADService.asmx/GetADCode?ADID=1")
var s=docSubmit.documentElement.text
window.alert(s)
td_AD.ierHTML=
#125
//setInterval(chang,2000);//间隔执行
lt;/script>
注意:
在fromework1.0和1.1是有区别的,
在1.1的 machine.config (C:\WIT\Microsoft.NET\Framework\v1.1.4322\CONFIG),默认weervice去除了post,get方法
你可在你的 machine.config 中加上 或者 只在 weervices 项目的 Web.config 的<ystem.wegt;里加上:
<weervicegt;
<rotocolgt;
<add name="Httost" />
<add name="HttpGet" />
</protocolgt;
</weervicegt;
否则,在ie地址栏输入 weervices 访问地址串时,提示:请求格式无法识别。
还有
docSubmit = new ActiveXObject("MSXML2.DOMDocument") //1.0
换成
docSubmit =new ActiveXObject("Microsoft.XMLDOM") //1.1
--------------------------
web服务方法:
[WebMethod]
ublic string GetData(string maxval)
#123
aseCla.DbManagerSql dbm=new BaseCla.DbManagerSql();
tring strSql="select * from s_KeShi where Keshidm>"+maxval;
DataSet ds=dbm.Query(strSql);
return ds.GetXml();
#125;
返回的xml数据:
<?xml version="1.0" encoding="utf-8" ?>
<tring xml="http://tempuri.org/">
<ewDataSet>
<dgt; <KeShidm>6</KeShidm> <KeShimch>财务部</KeShimch> </dgt;
<dgt; <KeShidm>7</KeShidm> <KeShimch>政工部</KeShimch> </dgt;
<dgt; <KeShidm>8</KeShidm> <KeShimch>安质部</KeShimch> </dgt;
<dgt; <KeShidm>9</KeShidm> <KeShimch>电管部</KeShimch> </dgt;
<dgt; <KeShidm>10</KeShidm> <KeShimch>运输公司</KeShimch> </dgt;
<dgt; <KeShidm>11</KeShidm> <KeShimch>局长</KeShimch> </dgt;
<dgt; <KeShidm>202</KeShidm> <KeShimch>变电站</KeShimch>lt;/dgt;
</NewDataSet>
</string>