I am trying to make autocomplete function which starts suggesting from datatable when users types. It seems all right but it pops up Not Found. In my database all columns name and connections seems to be alright. I don't understand where is the problem as it's even not throws any errors. This is the link of files I uploaded on server
ASPX
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
<link href="jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.0.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.22/jquery-ui.js"></script>
<script type="text/javascript">
$(function () {
$("#area").autocomplete({
source: function (request, response) {
var param = { cityname: $('#area').val() };
$.ajax({
url: "Dafault.aspx/GetAreas",
data: JSON.stringify(param),
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
dataFilter: function (data) { return data; },
success: function (data) {
response($.map(data.d, function (item) {
return {
value: item
}
}))
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert(errorThrown);
}
});
},
minLength: 2//minLength as 2, it means when ever user enter 2 character in TextBox the AutoComplete method will fire and get its source data.
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div class="form-items">
Select Area<br />
<asp:TextBox ID="area" CssClass="area" runat="server"></asp:TextBox>
</div>
VB
Imports System.Data
Imports MySql.Data.MySqlClient
Imports System.Configuration
Imports System.Web.Services
Partial Class _Default
Inherits System.Web.UI.Page
<WebMethod>
Public Shared Function GetAreas(areaname As String) As List(Of String)
Dim area As New List(Of String)()
Dim con As New MySqlConnection("Data Source=182.50.133.88;port=3306;Initial Catalog=db;User Id=user;password=pwd;")
Dim query As String = String.Format("SELECT areaName FROM areas", areaname)
'Note: you can configure Connection string in web.config also.
Dim cmd As New MySqlCommand(query, con)
con.Open()
Dim reader As MySqlDataReader = cmd.ExecuteReader()
While reader.Read()
area.Add(reader.GetString(0))
End While
Return area
End Function
End Class
Dafaultinstead ofDefault.queryfor your case. If you debug it, what does it generate? What SQL string?