Trying to make a call to this web service via AJAX...
The structure of the web service is as shown below
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public String countryCode(String input)
{
StringBuilder strings = new StringBuilder("", 10000);
String text = System.IO.File.ReadAllText(Server.MapPath("countryCodes.txt"));
String[] countries = Regex.Split(text, "#");
var valids = new List<String>();
foreach (String c in countries)
{
if (c.ToUpper().StartsWith(input.ToUpper()) || c.ToLower().StartsWith(input.ToLower()))
{
if (input == "")
{
break;
}
valids.Add(c);
}
}
return (valids.Any()) ? String.Join(" ", valids) : "No results found for your input!";
}
}
I have created a blank web form and included the service reference in the script manager like this
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/WebService1.asmx" />
</Services>
</asp:ScriptManager>
Here is the javascript code I am using
<script type= "text/javascript">
var a = wRequest.set_userContext("user's context");
var onClick = function () {
CountryCodes.WebService1.countryCode($get("TextBox1"), onSuccess, onFailed);
}
var onSuccess = function (result) {
$get("Label3").innerHTML = result;
}
var onFailed = function (result) {
$get("Label3").innerHTML = "No results found for your input!";
}
</script>
When I click the button, nothing happens. The button code is as follows
<input type="button" value="Find Country Codes " onclick ="onClick()" />
The button, textbox, and label code are in the same location. What am I doing wrong and how can it be resolved?
If you need further clarification, please comment below. Thank you.
Regards
EDIT : I have commented out this line in the web service
"[System.Web.Script.Services.ScriptService]"