D_D
D_D

Reputation: 1049

Ajax Json multiple parameters

This code below sitting on a ASP.Net application on the Site.Mater....

I need to pass another two parameters from the default.aspx page, one asp:label and one asp:textbox

What is the easiest way to do that?

Thanks

     <script type="text/javascript">
        $(function () {
                $(".tb").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        url: "TestWebService.asmx/FetchList",
                        data: "{ 'testName': '" + request.term + "'}",
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        dataFilter: function (data) { return data; },
                        success: function (data) {
                            response($.map(data.d, function (item) {
                                return {
                                    value: item.Name

                                }
                            }))
                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            alert(textStatus);
                        }
                    });
                },
                minLength: 2

            });
        });

Upvotes: 0

Views: 8286

Answers (1)

yaka
yaka

Reputation: 914

In your jQuery autocomplete, You need to change your data parameter to this:

data: "{ 'testName': '" + request.term + "' ,lbl: '" + $(".lblClass").text() + "' ,txt: '" + $(".txtClass").val() + "'}"

And then change your service method like this:

[WebMethod]
public List<string> FetchList(string testName, string lbl, string txt)
{
  //...
}


Note: .lblClass and .txtClass are classes for ASP:Lable and ASP:TextBox respectively.

Upvotes: 2

Related Questions