2011-05-26 122 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> 
相關問題