Firefox在Ajax上调用Asmx

时间:2017-02-28 18:51:05

标签: javascript c# jquery asp.net

最近,Firefox停止向我们在.asmx.cs页面中的WebService WebMethod发送Ajax调用。基本上,FF甚至没有试图打这个电话。我见过其他类似问题的帖子,但到目前为止我还没有找到任何解决方案。这在以前从来就不是问题(好像新的FF更新是罪魁祸首),以下似乎在Chrome和IE中运行得很好。这是Javascript:

<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 个答案:

答案 0 :(得分:0)

嗯,这很令人尴尬,但这就是我发现的。 add blocker addon&#39; Add Block Plus&#39;因为Firefox阻止了这个ajax调用。但是,应该注意的是,我实际上在其中设置了一个单独的Web窗体测试解决方案,其中包含Web服务(asmx.cs)并对其进行了测试。并且ajax通过Firefox调用ADP工作。因此,我公司的产品与Firefox / ADP结合使用是一个糟糕的组合。幸运的是,我们不支持ADP,所以我不认为这将是一个问题。然而,这就是我发现的。