I am trying to execute the below code for AutoComplete, but when I debug/execute the code. I noticed itsnot hitting my web method.
ASPX Code
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="Styles/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" type="text/css" />
<script src="Scripts/jquery-1.10.2.js" type="text/javascript"></script>
<script src="Scripts/jquery-ui-1.10.4.custom.min.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function () {
SearchText();
});
function SearchText() {
$('#<%=TextBox1.ClientID %>').autocomplete({
source: function (request, response) {
var param = { searchStr: $('#TextBox1').val() };
$.ajax({
type: 'POST',
contentType: "application/json; charset=utf-8",
url: "WebForm1.aspx/GetCountry",
// data: "{searchStr:JSON.stringify('u')}",
data: "{searchStr: 'xx'}",
//data: JSON.stringify(param),
dataType: "json",
success: function (data) {
response(data.d);
},
error: function (msg, text) {
alert(msg);
}
});
}
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1" runat="server">
</form>
</body>
</html>
C# code behind code
[WebMethod(EnableSession = true)]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public static string[] GetCountry(string searchStr)
{
List<string> listCt = new List<string>();
listCt.Add("UnitedStates");
listCt.Add("UnitedKingdom");
listCt.Add("UnitedArab");
listCt.Add("UnitedNations");
return listCt.ToArray();
}