我正在使用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
当我尝试执行自动填充时,它会给我一个错误 POST http://ab99.pricecompareindia.com/Service/AutoHelp.asmx/CustomerList 500(内部服务器错误) 但我试图直接从浏览器执行服务,它给我一个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/
运行任何人都可以帮助我。 在此先感谢。
答案 0 :(得分:0)
将此行放在您的ajax中: 数据:'{“前缀”:“'+ request.term +'”}', 它会像我一样发生。