CSDN博客

img eastfreeman

Web Service的客户端javascript调用

发表于2004/7/14 11:06:00  674人阅读

<html>
<head>
<script language="JavaScript">
var iCallID;
var service_MsgXML = new ActiveXObject("MSXML.DOMDocument");
function init()
{
 service.useService("
http://gengw/jyjd/service/service.asmx?WSDL","service");
 iCallID = service.service.callService("GetUserList",7);
}


</script>
</head>
<body onload="init()">
<div id="service" style="behavior:url(
http://gengw/chat/webservice.htc)" onresult="onWSresult()">
</div>
<SCRIPT language="JavaScript1.2">
function onWSresult()

    if((event.result.error)&&(iCallID==event.result.id)) 
 {   
  var xfaultcode = event.result.errorDetail.code;
  var xfaultstring = event.result.errorDetail.string;   
  var xfaultsoap = event.result.errorDetail.raw;
  alert(xfaultstring);
  // Add code to output error information here
 }
 else
 {
    var xmlResult = event.result.raw.xml;
  //  var result = event.result.value;
  //  alert(result);
    if (xmlResult != "" && xmlResult != null)
        {

  service_MsgXML.loadXML(xmlResult);
     maxNum = service_MsgXML.getElementsByTagName("msgcontent").length
  column=service_MsgXML.getElementsByTagName("msgcontent").item(0).childNodes
  alert(maxNum);
        service_ChatMsgs.innerHTML = "";
  for (m=0;m<=maxNum-1;m++){
  //for(x in service_MsgXML.documentElement.childNodes)
  //alert("The method returned the result : " + xmlResult);
 // service_ChatList.innerText = service_MsgXML.selectSingleNode("//msgtime").text;
 // service_ChatList.scrollTop = 2000;
    // mName=column.item(m).tagName;
     service_ChatMsgs.innerHTML += service_MsgXML.getElementsByTagName("msgtime").item(m).text+":<br>";
     service_ChatMsgs.innerHTML += service_MsgXML.getElementsByTagName("msgcontent").item(m).text+"<br>";
  //service_ChatMsgs.innerHTML += "<br>";
  //service_ChatMsgs.innerHTML += service_MsgXML.selectSingleNode("//msgcontent").text;
  //service_ChatMsgs.scrollTop = 2000;
  }  
  }
    window.setTimeout('iCallID = service.service.callService("GetUserList",7);',3000);
 }
}
</script>
<Div id="service_ChatMsgs" style="Height:100%;Width:100%;Overflow:Auto;"></Div>
</body>
</html>

0 0

相关博文

我的热门文章

img
取 消
img