0

//When focusout event is working, tested with alert.. but ajax call is not working and my aspx.cs method also not firing.. Please solve this issue. //This is my aspx page jquery code.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<script type="text/javascript">
    $(document).ready(function () {
        var elem = document.getElementById('<%=txtProduct.ClientID %>');

        $(elem).focusout(function () {
            myF($(this).val());
        });

        function myF(value) {
            var fist = value.split(' ( ', 1);
            $.ajax({
                type: 'POST',
                url: 'Invoice.aspx/getProductDetails',                   
                data: "{'strCode':'" + fist + "'}",
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: function (response) {
                    alert(response.d.toString());
                },
                failure: function (response) {
                    alert('error');
                }
            });
        }
    });
</script>

//Server side code

    [WebMethod]
    public static string getProductDetails(string strCode)
    {
        List<string> companyInfo = new List<string>();
        companyInfo.Add(HttpContext.Current.Cache[Convert.ToString(HttpContext.Current.Session["UserID"]) + "CompanyID"].ToString());
        companyInfo.Add(strCode);
        List<string> price = Database.MasterDB.getProductInfo(companyInfo);
        if (price.Count > 0)
            return price[0].ToString();
        else
            return "000";
    }
4

1 回答 1

0

由于您在 Web 方法中使用 Session 事物,因此可能会给出空值或空值。这是因为您没有为 webmethod 启用会话。

像这样—— [WebMethod(EnableSession=true)]

阅读更多

于 2014-11-28T18:52:15.070 回答