0
I’m trying to make an autocomplete, but is giving the following error, not even make the post...
My code is like this:
<script type="text/javascript">
$(function () {
$("[id$=DsValor]").autocomplete({
source: function (request, response) {
$.ajax({
url: '@Url.Action("GetPalavraChave", "HomeCanal")',
data: "{ 'prefixo': '" + request.term + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
response($.map(data.d, function (item) {
return {
label: item.split('-')[0],
val: item.split('-')[1]
}
}))
},
error: function (response) {
alert(response.responseText);
},
failure: function (response) {
alert(response.responseText);
}
});
},
select: function (e, i) {
$("[id$=hfCustomerId]").val(i.item.val);
},
minLength: 1
});
});
And the backend is like this:
[WebMethod]
public static string[] GetPalavraChave(string prefixo)
{
List<string> clientes = new List<string>();
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = ConfigurationManager.ConnectionStrings["WhiteLabelVOD"].ConnectionString;
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandText = "SELECT * FROM Palavra_Chave WHERE Ic_Ativo = 1 AND Ds_Palavra_Chave LIKE @Texto + '%'";
cmd.Parameters.AddWithValue("@Texto", prefixo);
cmd.Connection = conn;
conn.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
clientes.Add(string.Format("{0}-{1}", sdr["ContactName"], sdr["CustomerId"]));
}
}
conn.Close();
}
}
return clientes.ToArray();
}
You have a mistake in
jquery-ui.theme.css
, Did you alter that file? And in order to help we need to see more of your front only the autocomplete code doesn’t help, because the second error isn’t related to it either– Leandro Angelo