1

我正在使用 ASP.net 页面方法。我遇到的这个问题是它不适用于某些浏览器。例如 IE、Opera Safari 和新的 Firefox。它适用于 Chrome。我发现了这一点,但对我的情况没有帮助http://www.carlj.ca/2008/06/18/fixing-firefoxs-ns_error_not_available-error-when-using-pagemethods/任何帮助将不胜感激。

<asp:ScriptManager ID=”scManager″ enablepagemethods=”true” runat=”server” />
<asp:Button ID="btnBuyNow" runat="server" Text="Buy Now" OnClientClick="AddProductToCart()" />

<script type="text/javascript">
   function AddProductToCart() {
      //hard coded values for testing, productId, quantity
      PageMethods.AddProduct(142, 1);
      window.location.href = '../Cart.aspx';
   }
</script>

[System.Web.Services.WebMethod]
public static void AddProduct(string prodId, string quantity)
{
    //adding product to cart
    //When testing with Chrome breakpoint is hit,
    //All other browsers dont hit break point
    CurrentCart.AddProduct(prodId, quantity);
}
4

2 回答 2

0
  <script language="javascript" type="text/javascript">
        $(document).ready(function() {
            $('#Save').click(InsertClient);
        }
    );
        function InsertClient() {
            var BizName = $('#txtBizName').val();
            alert(BizName);
            $.ajax({
                url: "Common.asmx/InsertClient",
                type: "POST",
                dataType: "json",
                data: "{BizName:'" + BizName + "'}",
                contentType: "application/json; charset=utf-8",
                success: function(msg) {
                    $('#status').html('Id: '+msg['d']['Id']);
                },
                error: function(e) {
                    $('#status').innerHTML = "Unavailable";
                }
            });
        }
    </script> 



in Common.asmx write webmethod as follow

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public Client InsertClient(string BizName)
{
    Client objClient = new Client();
    objClient.BizName = BizName;
    InsertData(objClient);
    return objClient;
}
于 2013-01-31T10:56:41.170 回答
0

对此可能有更好的解决方案,但这是最终奏效的唯一方法。

<script type="text/javascript">

function AddProductToCart() {

  //hard coded values for testing, productId, quantity
  PageMethods.AddProduct(142, 1);

  var millisecondsToWait = 500;
           setTimeout(function () {
               window.location.href = '../Cart.aspx';
           }, millisecondsToWait);
       }
  </script>
于 2013-02-01T09:30:29.167 回答