0
我有这样的自动完成代码:jQuery用户界面自动完成需要额外的功能
$("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);
}
}
}
如果您的意思是将url更改为AjaxSearch.aspx?a = getspots&c = updateSpotList&q = request.term并删除数据,则问题仍然存在。 – UngaBunga 2010-12-20 12:09:47
我不知道。不要使用数据: 使用来源:AjaxSearch.aspx?a = getspots&c = updateSpotList 然后它会自动添加到URL的术语。 – MartinHN 2010-12-20 15:11:36
我已经更新了我的答案,以便更详细。 – MartinHN 2010-12-21 07:21:44