Question

Related to this: jquery doesnt go to error or success

I've got an old 1.1 asp.net/vb.net project that I need to add autocomplete to a textbox. I wrote a .asmx (the web service file) as such:

 <WebMethod()> _
    Public Function GetTags() As String()
        Dim arr() As String = BindTags()
        Return arr
    End Function
    Private Function BindTags() As String()
        Dim cmdSelect As SqlCommand
        Dim conMyData As SqlConnection
        Dim reader As SqlDataReader
        Dim myList As New ArrayList

        'try and make a connection   
        Try
            conMyData = New SqlConnection(ConfigurationSettings.AppSettings("strConn"))
            cmdSelect = New SqlCommand("select_tags_grid", conMyData)

            With cmdSelect
                .CommandType = CommandType.StoredProcedure
                'add parameters
                .Parameters.Add("@SortOrder", SqlDbType.TinyInt).Value = 1
                'check the clientid
                conMyData.Open()
                reader = cmdSelect.ExecuteReader(CommandBehavior.CloseConnection)
            End With

            While (reader.Read())
                myList.Add(CType(reader("Tag"), String))
            End While

            Dim arr() As String = CType(myList.ToArray(Type.GetType("System.String")), String())
            Return arr
        Catch e As Exception
            'clean up and close resources
            Throw e
        Finally
            cmdSelect = Nothing
            conMyData.Close()
            conMyData = Nothing
        End Try
    End Function

This works fine as I can see the data when I run this .asmx file. Then I've read articles upon articles that say .net 1.1 did not support json / jsonp format and to use xml. So then I went on to embark on the jquery side to attach this autocomplete ui to my textbox. Here is what I tried:

$("#txtTags").autocomplete({
    minLength: 0,
    source: function(request, response) {   
        $.ajax({
            type: "POST",
            url: "GetTags.asmx/GetTags",
            dataType: "xml",
            contentType: "text/xml; charset=utf-8",
      success: function(xml) {
           alert("hi");
           // Completion logic goes here
      },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert(textStatus);
            }
        });
    },    
});

Now when I run my app and use for instance google chrome I do not see any errors in the developer tools console pop up when I type in the textbox. So I am not sure if this is working or not. I tried to follow this stackoverflow answer: https://stackoverflow.com/a/7729147/168703 to see how this guy did it and i'm pretty sure I followed correctly? Can anyone tell what I am doing wrong please.

Was it helpful?

Solution

On chrome's tools go to the Network tab. Use the "clear" button to delete all entries and then start typing in your textbox. If autocomplete is working, an entry should appear in front of you (on the network tab) and clicking on it should give you details on what is going on.

enter image description here

In the above example I'm getting the call to the generic handler I use for the autocomplete. Since you are on 1.1 and you use a web service (if I unserstood correctly) you should see the web service call or something similar.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top