Click here to Skip to main content
15,885,782 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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();
}
Posted
Comments
Pradip Kumar Sen 21-May-15 7:34am    
Did this problem solved ?

I thing I found in your ajax call:
data: "{searchStr: 'xx'}",
You can remove this double coat here Like
data: {searchStr: 'xx'},

Is there anything error message you are getting or did you check with keeping a debugger inside error event ?

You can remove this content type from ajax call :
contentType: "application/json; charset=utf-8"

Please try above and let us know if you are getting any error.
Arun Kumar_Tech 22-May-15 0:19am    
please reffer the below link,
http://www.dotnetspan.com/2015/02/bind-gridview-using-jquery-json-ajaxcall-in-aspnet.html

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900