Can someone help me find the error in my code? I trying to make an autocomplete textbox. My code run in the other pages but in this particular page it gaves me an error. Here's the code snipet:
- <script type="text/javascript">
- $(document).ready(function () {
- $(".autosuggest").autocomplete({
- source: function (request, response) {
- $.ajax({
- type: "POST",
- contentType: "application/json;charset=utf-8",
- url: "AgentService.asmx/GetMatchingAgents",
- data: "{'agent':'" + document.getElementById('AgentNumber').value + "'}",
- dataType: "json",
- success: function (data) {
- response(data.d);
- },
- error: function (result) {
- alert("Agent ID not found.");
- }
- });
- }
- });
- });
- </script>
- <body>
- <form id="form1" runat="server">
- <div>
- <fieldset style="width: 500px;" class="ui-widget">
- <legend><strong>CI Issuance to Agents</strong></legend>
- <table>
- <tr>
- <td>CI Series #:
- </td>
- <td>
- <asp:TextBox ID="txtCISeries" runat="server"></asp:TextBox>
- </td>
- </tr>
-
- <tr>
- <td>Issued To:
- </td>
- <td>
- <input id="AgentNumber" runat="server" type="text" class="autosuggest" placeholder="Search agent name" />
- </td>
-
-
-
- public class AgentService : System.Web.Services.WebService
- {
-
- [WebMethod]
- public List<string> GetMatchingAgents(string agent)
- {
- List<string> agents = new List<string>();
- using (SqlConnection con = DBConnection.GetDbCon())
- {
- SqlCommand cmd = new SqlCommand("spGetMatchingAgents", con);
- cmd.CommandType = CommandType.StoredProcedure;
- cmd.Parameters.AddWithValue("@AgentID", agent);
- con.Open();
- SqlDataReader rdr = cmd.ExecuteReader();
- while (rdr.Read())
- {
- agents.Add(rdr["AgentID"].ToString());
- }
- }
- return agents;
- }
- }
The webservice is working fine. I tried it and got the data. But when i call it from the webform it gives me this error: