0

Jquery で単純なオートコンプリート機能を使用しています。

ここにJavaスクリプトコードがあります

    $(document).ready(function () {
        $("#AutoCompleteText").autocomplete({
            source: function (request, response) {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "/Service/AutoHelp.asmx/CustomerList",
                    dataType: "json",
                    data: "{}",
                    success: function (data) {
                        response($.map(data.d, function (item) {
                            return {
                                label: item.TEXT + '(' + item.ID + ')',
                                value: item.ID,
                                name: item.TEXT
                            }
                        }))
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        console.log("In The ERROR");
                        console.log(XMLHttpRequest);
                        console.log(textStatus);
                        console.log(errorThrown);
                    }
                });
            },
            minLength: 1
        });
    });

これがWebサービスコードです

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel
Imports System.Web.Script.Services

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
' <System.Web.Script.Services.ScriptService()> _
<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class AutoHelp
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function HelloWorld() As String
        Return "Hello World"
    End Function

    Public Class dbHelpData
        Dim _id As String
        Dim _text As String

        Public Property ID As String
            Get
                Return _id
            End Get
            Set(ByVal value As String)
                _id = value
            End Set
        End Property

        Public Property TEXT As String
            Get
                Return _text
            End Get
            Set(ByVal value As String)
                _text = value
            End Set
        End Property

    End Class

    <WebMethod()> _
    <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
    Public Function CustomerList() As List(Of dbHelpData)
        Dim CustList As New List(Of dbHelpData)

        Dim mCustList As dbHelpData
        mCustList = New dbHelpData
        mCustList.ID = "1"
        mCustList.TEXT = "Kartik"
        CustList.Add(mCustList)

        mCustList = New dbHelpData
        mCustList.ID = "2"
        mCustList.TEXT = "Sarika"
        CustList.Add(mCustList)

        mCustList = New dbHelpData
        mCustList.ID = "3"
        mCustList.TEXT = "Yashika"
        CustList.Add(mCustList)

        Return CustList
    End Function

End Class

AutoFill を実行しようとすると、POST http://ab99.pricecompareindia.com/Service/AutoHelp.asmx/CustomerList 500 (Internal Server Error) というエラーが表示されますが、ブラウザーから直接サービスを実行しようとすると、以下のような XML 出力ビューを表示します。

<ArrayOfDbHelpData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
    <dbHelpData>
        <ID>1</ID>
        <TEXT>Kartik</TEXT>
    </dbHelpData>
    <dbHelpData>
        <ID>2</ID>
        <TEXT>Sarika</TEXT>
    </dbHelpData>
    <dbHelpData>
        <ID>3</ID>
        <TEXT>Yashika</TEXT>
    </dbHelpData>
</ArrayOfDbHelpData>

私が間違っていることを理解するのは難しいです。完全なコードはhttp://ab99.pricecompareindia.com/で実行されています。

誰でも私を助けてください。前もって感謝します。

4

1 に答える 1

0

ajax: data: '{ "prefix": "' + request.term + '"}' に次の行を追加すると、私の場合とまったく同じように機能します。

于 2013-12-09T11:16:10.223 に答える