jquery自动完成中的额外参数

时间:2017-04-05 12:46:25

标签: c# asp.net jquery-ui

我是asp.net和Jquery的新手。我在代码中传递和使用其他参数时遇到了一些困难;我试图将TxtSiteName和txtAccount传递给代码,以便将它们用作我存储的prodcedure中的参数;

<script type="text/javascript" lang="javascript">
    $(function () {
        $("#txtAccount").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        url: "RequisitionService.asmx/GetAccount",
                        data: {
                            term: request.term,
                            Site: $("#txtSiteName").val(),
                            Account: $("txtAccount").val()
                        },
                        type: "POST",
                        dataType: "json",
                        contentType: "application/json;charset=utf-8",
                        success: function (data) {
                            response(data.d);

                        },
                        error: function (result) {
                            alert('There is a problem processing your request');
                        }
                    });
                },
                minLength: 0
            });
        });
   </script>

[WebMethod]
    public List<string> GetAccount(String Site, String Account)
    {
        String CS = "data source = ****; database= ****; user id = ****; Password=****";
        List<string> Accounts = new List<string>();
        using (SqlConnection con = new SqlConnection(CS))
        {

            SqlCommand cmd = new SqlCommand("GetAccount", con);

            cmd.CommandType = CommandType.StoredProcedure;

            SqlParameter parameter = new SqlParameter("@site",Site);
            cmd.Parameters.Add(parameter);

            con.Open();

            SqlDataReader rdr = cmd.ExecuteReader();
            while (rdr.Read())
            {
                Accounts.Add(rdr["GLAccountDesc"].ToString());
            }
        }

        return Accounts;

0 个答案:

没有答案