Sto cercando di usare jQuery AutoComplete ma tutto quello che ottengo è un singolo oggetto con tutti i risultati in esso contenuti.
Ho questo WebMethod di ASP.Net:
[WebMethod]
public static string FetchCompletionList(string term)
{
var json = JsonConvert.SerializeObject(CustomerProvider.FetchKeys(term, 8));
return json;
}
essere chiamato da questo script:
$("[id$="txtLKey"]").autocomplete({
minlength: 2,
source: function(request, response) {
$.ajax({
type: "POST",
url: "/Views/Crm/Json/Json.aspx/FetchCompletionList",
data: "{term: "" + $("[id$="txtLKey"]") .val() + "", count: "8"}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
response(data);
},
error: function (jqXHR, textStatus, errorThrown) {
alert(jqXHR.responseText);
alert(textStatus);
alert(errorThrown.toString());
}
});
}
});
E il risultato è questo:
Quando quello che voglio veramente è una lista di opzioni che l'utente può selezionare, ogni NZ dovrebbe essere un elemento in una lista.
risposte:
0 per risposta № 1Ci sono due problemi qui,
- devi passare
data.d
aresponse
piaceresponse(data.d)
. - la tua stringa di valori non è valida dovrebbe essere
{"d":["NZ0008","NZ0015","NZ0017","NZ0018","NZ0026","NZ0027","NZ003??1","NZ0035"]}