Asp.net jquery ui自动完成需要额外的功能

Asp.net jquery ui自动完成需要额外的功能,asp.net,jquery,user-interface,autocomplete,jquery-autocomplete,Asp.net,Jquery,User Interface,Autocomplete,Jquery Autocomplete,我有这样的自动完成代码: $("input#PickupSpot").autocomplete({ source: function(request, response){ $.ajax({ url: "AjaxSearch.aspx", dataType: "jsonp", data: { a: "getspots", c: "updateSpotList", q:

我有这样的自动完成代码:

$("input#PickupSpot").autocomplete({
  source: function(request, response){
     $.ajax({
        url: "AjaxSearch.aspx",
        dataType: "jsonp",
        data: {
           a: "getspots",
           c: "updateSpotList",
           q: request.term
        },
        success: function(){
           alert("Success");
        },
        error: function (xhr, ajaxOptions, thrownError){
                alert(xhr.status);
                alert(thrownError);
        }

     });
  }
}))

当我试图获取数据时,Firebug显示一个错误:“updateSpotList未定义”。 我需要创建一个名为updateSpotList的函数来从服务器获取响应。并且从不调用成功警报

为什么我需要这个功能?也许在aspx中定义了一些东西?它是:

string response = "";

 string callback = Request.QueryString["c"];
 string action = Request.QueryString["a"]; 
 string query = Request.QueryString["q"];

  //Ensure action parameter is set
  if(action != null && action.Equals("getspots")){
        //Ensure query parameter is set
        if (query != null && query.Length > 0){
            SpotListRequest request = new SpotListRequest
            {
                FreeText = query,
                Language = "sv-SE"
            };
            IEnumerable<Spot> spots = DataBridge.GetSpotList(null, null, query).OrderBy(i => i.FullName);

            JavaScriptSerializer js = new JavaScriptSerializer();

            string json = js.Serialize(spots.ToArray());

            //Ensure callback parameter is set
            if (callback != null && callback.Length > 0)
            {
                response = String.Format("{0}('{1}')", callback, json);
            }
        }
    }
string-response=“”;
string callback=Request.QueryString[“c”];
string action=Request.QueryString[“a”];
字符串query=Request.QueryString[“q”];
//确保已设置操作参数
if(action!=null&&action.Equals(“getspots”)){
//确保已设置查询参数
if(query!=null&&query.Length>0){
SpotListRequest=新SpotListRequest
{
FreeText=query,
语言=“sv SE”
};
IEnumerable spots=DataBridge.GetSpotList(null,null,query).OrderBy(i=>i.FullName);
JavaScriptSerializer js=新的JavaScriptSerializer();
字符串json=js.Serialize(spots.ToArray());
//确保已设置回调参数
if(callback!=null&&callback.Length>0)
{
response=String.Format(“{0}('{1}')”,回调,json);
}
}
}

您可以指定URL作为源参数,而不是数据参数

插件将向您的服务器发出请求,您应该返回一个JSON数组,如下所示:

[{label:“Name”},{label:“Name 2”}]

将JavaScript代码更改为:

$("input#PickupSpot").autocomplete({
  source: "AjaxSearch.aspx?a=getspots&c=updateSpotList"
});
autocomplete插件将在源URL中附加一个名为term的参数以及输入元素的当前值,因此如果您在输入元素中编写了test,则会请求:“AjaxSearch.aspx?a=getspots&c=updateSpotList&term=test”


在服务器上,您希望将q更改为term。

如果您的意思是将url更改为AjaxSearch.aspx?a=getspots&c=updateSpotList&q=request.term并删除数据,则问题仍然存在。我不这么认为。不使用数据:使用source:AjaxSearch.aspx?a=getspots&c=updateSpotList,然后它会自动将该术语添加到URL中。谢谢,但这并没有解决我的问题。如果我使用“源代码”,则根本不会创建对服务器的请求,如果使用“url”,则需要像前面一样使用updateSpotList。请尝试我刚刚更新的代码。然后,您可能需要将响应从JSONP更改为常规JSON数组。这就是漏洞问题——我无法在服务器上更改文件。