1

this is my web method:

[WebMethod]
    public string getitemamount(string item_name)
    {
        DataTable dt = da.executequery("select unit_price from item_details where item_name='" + item_name.ToString() + "'");
        string a = dt.Rows[0]["unit_price"].ToString();
        return a;
    }

This is my ajax:

<script language="javascript" type="text/javascript">
            $(function() {

                $("#" + '<%=ddl_item.ClientID %>').change(function() {
                        $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "WebService2.asmx/getitemamount",
                        data: "{'item name':'" + $("#" + '<%=ddl_item.ClientID %> option:selected').val() + "'}",
                        dataType: "json",
                        success: function(msg) {
                            var data = eval("(" + msg.d + ")");
                            alert(msg.d);
                            $("#" + '<%=txt_unitprice.ClientID %>').empty();
                            for (var i = 0; i < msg.d.length; i++) {
                                var unit = data[i].unitprice;
                                $("#" + '<%=txt_unitprice.ClientID %>').val(unit);
                                $("#" + '<%=txt_unitprice.ClientID %>').val($("#" + '<%=txt_unitprice.ClientID %>').val());
                            }
                        },
                        error: function(re) { alert(re.toString() + " FROM ERROR"); }
                    });
                });
            });
</script>

when i run a webservice its working ..when i calling webmethod using ajax its returning object object error....thanks in advance pl help me

4

0 回答 0