最近,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>
瀏覽器控制檯似乎沒有顯示任何錯誤。
你在Firefox的控制檯中調試過它嗎?它實際上是否到達「$ .ajax(」調用? – JuanR
帖子中的代碼沒有顯示問題(假設頁面從'http:// localhost'呈現,沒有端口/相同的架構)。允許重現這個問題 –
Juan,是的,我已經在Firefox的控制檯中進行了調試,並且它到達了ajax。就像我說的,在其他瀏覽器中一切正常。 – McCrockett