2017-02-28 21 views
0

最近,Firefox停止向我們在.asmx.cs頁面中的WebService WebMethod發送Ajax調用。基本上,FF甚至不會試圖打這個電話。我看過其他有類似問題的帖子,但到目前爲止我還沒有找到任何解決方案。這從來沒有成爲一個問題(如果一個新的FF更新是罪魁禍首),以下似乎在Chrome和IE中工作得很好。這是JavaScript:Firefox在Ajax調用Asmx時停頓

<script> 
$(document).ready(function() { 
    var hash = 'JzVpYbr48'; 
    var dataS = JSON.stringify({ sessionHash: hash, customerID: '010000' }); 

    $('#foo').on('click', function (event) { 
     event.preventDefault(); 

     $.ajax({ 
      type: 'POST', 
      url: "http://localhost/MVRC/ad.asmx/GetAchievementsSummary", 
      contentType: 'application/json;charset=utf-8', 
      dataType: 'json', 
      data: dataS, 
      success: function (res) { 
       console.log("badges success"); 
      }, 
      error: function (res) { 
       console.log("badges failure"); 
      } 
     }); 

    }); 
}); 
</script> 

這基本上是後面的代碼:

[WebService(Namespace = "http://www.ourdomain.com/mvrc")] 
[WebServiceBinding(ConformsTo = WsiProfiles.None)] 
[System.ComponentModel.ToolboxItem(false)] 
[System.Web.Script.Services.ScriptService] 
public class ad : System.Web.Services.WebService 
{ 

    [WebMethod] 
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
    public object GetAchievementsSummary(string sessionHash, string customerID) 
    { 
     return new { foo = "blah", bar = "blah" }; 
    } 
} 

而對於它的價值,這裏有從web.config幾個可能的相關片段:

<location path="ad.asmx"> 
    <system.web> 
    <webServices> 
     <protocols> 
     <add name="HttpGet" /> 
     <add name="HttpPost" /> 
     </protocols> 
     <conformanceWarnings> 
     <remove name="BasicProfile1_1" /> 
     </conformanceWarnings> 
    </webServices> 
    </system.web> 
</location> 
<system.webServer> 
    <httpProtocol> 
     <customHeaders> 
      <add name="Access-Control-Allow-Origin" value="*" /> 
      <add name="Access-Control-Allow-Headers" value="Content-Type" /> 
     </customHeaders> 
    </httpProtocol> 
</system.webServer> 

瀏覽器控制檯似乎沒有顯示任何錯誤。

+1

你在Firefox的控制檯中調試過它嗎?它實際上是否到達「$ .ajax(」調用? – JuanR

+0

帖子中的代碼沒有顯示問題(假設頁面從'http:// localhost'呈現,沒有端口/相同的架構)。允許重現這個問題 –

+0

Juan,是的,我已經在Firefox的控制檯中進行了調試,並且它到達了ajax。就像我說的,在其他瀏覽器中一切正常。 – McCrockett

回答

0

嗯,這很尷尬,但這裏是我發現的。 Firefox的add block addon'Add Block Plus'阻止了這個ajax調用。但是,應該指出的是,我實際上已經建立了一個單獨的Web Forms測試解決方案,並在其中包含一個Web服務(asmx.cs)並進行了測試。通過與ADP工作的Firefox的ajax調用。因此,我公司的產品與Firefox/ADP相結合是一個糟糕的組合。幸運的是,我們不支持ADP,所以我不認爲這會是一個問題。不過,這是我發現的。