I am doing an autocomplete, via AJAX
, which enters the Web service, "search in the Bank" and returns me a String in the format JSON
.
I have to transform the JSON
down into a list to iterate over it.
In data.d
I get the following String:
"[{"IDPais":1,"Pais1":"Brasil","IDIdioma":1}]"
When reading the file JSON
with the function $.map
it gives error in the console.
My code:
$(function() {
$("#<%=txtPais.ClientID%>").autocomplete({
source: function(request, response) {
$.ajax({
url: '<%=ResolveUrl("../ws/AutoComplete.asmx/GetListaPais")%>',
data: "{ 'prefixText': '" + request.term + "','contextKey': '" + $("#<%=rblIdiomas.ClientID%> input:checked").val() + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function(data) {
response($.map(data.d, function(item) {
return {
label: item.Pais1,
val: item.IDPais
}
}))
},
error: function(response) {
alert(response.responseText);
},
failure: function(response) {
alert(response.responseText);
}
});
},
minLength: 1
});
});