以下是我在javascript里面调用C# web服务(即调用asmx文件)的代码,
我在服务器机用是没有问题的,能正常取出XML文件出来,
但是在客户机用就出错,提示 xmlDOC.documentElement 为空或不是对象.
我估计是客户机没有权限访问服务器的web服务文件,
应该如何解决呢???? index=0;
div1.innerHtml ="";
var strRequest = "keyword="+Text1.value;
objHTTP=new ActiveXObject("MSXML2.XMLHTTP");
xmlDOC=new ActiveXObject("MSXML2.DOMDocument");
xmlDOC.async=false;
objHTTP.open("POST","SearchTitles.asmx/doSearch",false);

objHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
objHTTP.Send(strRequest);
xmlDOC.loadXML(objHTTP.responseText.replace(/&lt;/g,"<").replace(/&gt;/g,">"));
var s;
s="";
nodeList=xmlDOC.documentElement.getElementsByTagName("Table");
for (i=0;i<nodeList.length;i++)
{
s=s + "<div style=\"WIDTH:490px;\" class=\"gotTitle\" onmouseover=\"javascript:this.style.backgroundColor='lightblue'\" onmouseout=\"javascript:this.style.backgroundColor='white'\" onclick=\"return gotTitle_onclick()\">&nbsp;" + nodeList(i).selectSingleNode("Employee_Name_C").text + "</div>";
}

解决方案 »

  1.   

    你把IE的安全减低,容许javacript,和ActiveX能访问!
    或者是你客户端的IE没有MSXML2.DOMDocument这个组件!
      

  2.   

    我在服务器机里,
    在IE里用 http://localhost/aaa/abc.aspx 访问就正常,
    但用 http://www.abc.com/aaa/abc.aspx 就不行了.
    即同一个服务器机里,把localhost改成域名访问就不行.
    是什么问题呢?
      

  3.   

    自己解决了,
    在Web.config里面加上
    <webServices>
    <protocols>
    <add name="HttpPost" />
    <add name="HttpGet" />
    </protocols>
    </webServices>
    就可以了.