我正在使用 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
});
});
这是网络服务代码
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/
谁能帮帮我吗。提前致谢。