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