Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i want to auto implement textbox in vb.net using webservices my webservice codes works fine its give me result in xml file when i revoke it .
but in javascript its giveing me error i dont knw can some 1 help me.
thanks in advance.

my webservice code is ....


VB
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Collections.Generic
Imports System.Web



<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class companynameWebService
    Inherits System.Web.Services.WebService
    <WebMethod()> _
    Public Function GetStudentNames(ByVal searchTerm As String) As List(Of String)
        Dim studentNames As New List(Of String)()
        Dim cs As String = ConfigurationManager.ConnectionStrings("raulCS").ConnectionString
        Using con As New SqlConnection(cs)
            Dim cmd As New SqlCommand("spGetmatchingcompanyname", con)
            cmd.CommandType = CommandType.StoredProcedure

            Dim parameter As New SqlParameter("@Company", searchTerm)
            cmd.Parameters.Add(parameter)
            con.Open()
            Dim rdr As SqlDataReader = cmd.ExecuteReader()
            While rdr.Read()
                studentNames.Add(rdr("CompanyName").ToString())
            End While
        End Using
        Return studentNames
    End Function


End Class




my javascript code is : it giving me error function dnt knw why

XML
<script type="text/javascript" language="javascript">
       $(function () {

           $('#<%= txtsearch.ClientID %>').autocomplete({
               source: function (request, response) {
                   $.ajax({
                       url: "companynameWebService.asmx/GetStudentNames",
                       data: "{ 'searchTerm': '" + request.term + "' }",
                       type: "POST",
                       dataType: "json",
                       contentType: "application/json;charset=utf-8",
                       success: function (result) {
                           response(result.d);
                       },
                       error: function (result) {
                           alert('There is a problem processing your request');
                       }
                   });
               },
               minLength: 0
           });
       });
   </script>
Posted
Updated 15-Mar-14 11:49am
v2

Your error function can accept more parameters. See here: http://api.jquery.com/jQuery.ajax/[^]. One of the additional parameters will actually give you the error message.

In C# when you create a webservice you get this code right above your class name:
C#
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
   // [System.Web.Script.Services.ScriptService]


I'm not sure what the VB equivalent is but that may be what you are missing.
 
Share this answer
 
yup bro i already uncommneted that line of code and but then also it was generating that error
by-the-way i solved me probm thanx u replied
 
Share this answer
 

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