4

我正在尝试对此处找到的 jquery mobile 使用 Andy Matthews 自动完成功能。我的客户端服务有一个使用参数的方法。我不确定如何更改客户端调用以接受参数?

这是我的客户端调用:

  //WHERE DO I PUT INPUT PARAMETERS??

   $("#searchBox").autocomplete({
                method: 'POST',
                target: $('#suggestions'),
                source: "ClientService.svc/REST/GetStates",
                link: 'target.html?term=',
                minLength: 1

            });

这是我的服务:

   [OperationContract]
        [WebInvoke(Method = "POST", RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json)]
        public List<string> GetStates(string y)
        {
            List<string> x= GetData(y);
            return x;

        }
4

1 回答 1

3

查看源代码后,该插件似乎不允许传递自定义POST参数。用户在框中输入的内容是在一个名为 的参数中发送的term,但是如果您无法修改您的服务,我会做的是修改以下代码部分:

...
} else {
$.ajax({
    type: settings.method,
    url: settings.source,
    // Change the following line
    // data: { term: text },
    // for:
    data: { y: text },
...

它很容易找到,因为$.ajax整个插件中只有一个调用。

于 2012-11-14T17:20:05.160 回答