2011-05-26 120 views
2

我想访问使用Javascript在.Net中构建的web服务。在Firefox中使用javascript访问webservices时出现的问题

<html> 
<head> 
    <title>Test Web service</title> 

    <script type="text/javascript"> 

     function httptest(){ 

      var http = new XMLHttpRequest(); 
      var params = ""; 
      var RetFlag = "Webmail-"+ false;    
      http.open("Post", "http://localhost:3624/_anet/wsCoverageValidate.asmx/CheckCoverage" , false);   
      http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
      http.setRequestHeader("Content-length", params.length); 
      http.setRequestHeader("Connection", "close");  
      http.onreadystatechange = function() 
      { 
       if(http.readyState == 4 && http.status == 200) 
       { 
        var resp=http.responseText; 
        alert(resp); 
       } 
      }   
      http.send(params);  
     } 
    </script> 

</head> 
<body> 
    <div style="float: left; width: 100%; background-color: Gray;"> 
     <button id="btngo1" value="Go" type="submit" onclick="httptest()"> 
      Go 
     </button> 
    </div> 
</body> 
</html> 

这是我的html页面。现在,它可以在Internet Explorer中正常运行,但是它在从Firefox访问时会产生问题。它给我的javascript错误为

Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) 

,在错误控制台。我为此搜寻了很多,但没有成功。

请帮帮我。 谢谢

+0

任何帮助Firebug? – emaillenin 2011-05-26 09:26:01

+0

没有。同时调试JavaScript发送到功能,而Web服务已被访问。 – 2011-05-26 11:03:16

+0

尝试jQuery - 它是跨浏览器兼容 – emaillenin 2011-05-26 11:10:44

回答

4

我有我的问题的答案,它不能在本地进行测试。 Mozilla提供这种类型的安全性。

当我上传我的服务器上的HTML文件,并从我的PC调用,然后它工作正常。 ]

我从here

感谢所有的答案。

1

下载jQuery并在HTML页面添加源代码。

<script type="text/javascript" src="jquery.js"></script> 

按照本教程以获取更多信息 - http://docs.jquery.com/Tutorials:Getting_Started_with_jQuery

要访问web服务

<script type="text/javascript"> 

     function httptest(){ 

    $.post('http://localhost:3624/_anet/wsCoverageValidate.asmx/CheckCoverage', function(data) { 
     alert(data); 
    }); 
    </script> 
相关问题