'jQuery Autocomplete works on localhost but not working on remote server in asp.net

I have a pharmacy web application, written in vb.net, where a user searches for a medicine by name using the auto-complete function, which pulls data from the database table. This works perfectly on local host when debugging in Visual Studio, but does not work on a remote server host. Can someone please check my code and correct it?

Here is the .aspx code

    <script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.0.min.js" type="text/javascript"></script>
    <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/jquery-ui.min.js" type="text/javascript"></script>
    <link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/themes/blitzer/jquery-ui.css" rel="Stylesheet" type="text/css" />
    <script type="text/javascript">
        $(function () {
            $("[id$=txtSearch]").autocomplete({
                source: function (request, response) {
                    $.ajax({
                        url: '<%=ResolveUrl("~/AddMeds.aspx/GetNames/") %>',
                       data: "{ 'prefix': '" + request.term + "'}",
                       dataType: "json",
                       type: "POST",
                       contentType: "application/json; charset=utf-8",
                       success: function (data) {
                           response($.map(data.d, function (item) {
                               return {
                                   label: item.split('-')[0],
                                   val: item.split('-')[1]
                               }
                           }))
                       },
                       error: function (response) {
                           alert(response.responseText);
                       },
                       failure: function (response) {
                           alert(response.responseText);
                       }
                   });
               },
               select: function (e, i) {
                   $("[id$=hfNameId]").val(i.item.val);
               },
               minLength: 1
           });
       });
    </script>

Here is the .vb code

<WebMethod()>
Public Shared Function GetNames(prefix As String) As String()
    Dim customers As New List(Of String)()
    Using conn As New SqlConnection()
        conn.ConnectionString = ConnectionStrings("conString").ConnectionString
        Using cmd As New SqlCommand()
            cmd.CommandText = "SELECT top(10) [MedicineName], [IdNo] FROM [MedsName] where [MedicineName] like @SearchBar + '%'"
            cmd.Parameters.AddWithValue("@SearchBar", prefix)
            cmd.Connection = conn
            conn.Open()
            Using sdr As SqlDataReader = cmd.ExecuteReader()
                While sdr.Read()
                    customers.Add(String.Format("{0}-{1}", sdr("MedicineName"), sdr("IdNo")))
                End While
            End Using
            conn.Close()
        End Using
    End Using
    Return customers.ToArray()
End Function

image of working demo running locally

image of not working demo with error Running remotely with error



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source