我有一個像我下面的Web服務方法:自動完成JSON問題
<WebMethod()> _
Public Function TravelMeansList(ByVal prefix As String) As List(Of HRM_travellingMeans)
Dim ctx As New HRMEntities
Dim query = From c In ctx.HRM_travellingMeans Where c.name.ToUpper.StartsWith(prefix) Select c
If query.Count > 0 Then
Return query.ToList()
Else
Return Nothing
End If
End Function
和我的腳本像下面
<script type="text/javascript">
$(document).ready(function() {
$("#<%=travelmeansTextBox.ClientID %>").autocomplete({
source: function (request, response) {
$.ajax({
url: '<%=ResolveUrl("../../services/ApplicationService.asmx/TravelMeansList") %>',
data: "{ 'prefix': '" + request.term + "'}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
dataFilter: function (data) { return data; },
success: function (data) {
response($.map(data.d, function (item) {
return Json({
value: item.name
})
}))
},
error: function (response) {
alert(response.responseText);
},
failure: function (response) {
alert(response.responseText);
}
});
},
select: function (e, i) {
},
minLength: 1
});
});
</script>
我的問題是,任何時候我嘗試輸入我的文本框的任何字母i得到此錯誤
在System.Web.Script.Serialization.JavaScript中序列化\ u0027System.Data.Metadata.Edm.AssociationType \ u0027。「,」StackTrace「:」類型的對象時檢測到循環引用Serializer.SerializeValueInternal(Object o,StringBuilder sb,Int32 depth,Hashtable objectsInUse,SerializationFormat serializationFormat,MemberInfo currentMember)\ r \ n在System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o,StringBuilder sb,Int32 depth,Hashtable objectsInUse ,SerializationFormat serializationFormat,MemberInfo currentMember)\ r \ n System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o,StringBuilder sb,Int32 depth,Hashtable objectsInUse,SerializationFormat serializationFormat)\ r \ n。 Serialization.JavaScriptSerializer.SerializeValueInternal(Object o,StringBuilder sb,Int32 depth,Hashtable objectsInUse,SerializationFormat serializationFormat,MemberInfo currentMember)\ r \ n在System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o,StringBuilder sb,Int32 depth, Hashtable objectsInUse,SerializationFormat serializationFormat,MemberInfo currentMember)\ r \ n在System.Web .Script.Serialization.JavaScriptSerializer.SerializeEnumerable ......
我在做什麼錯。
發佈你的班級結構 – Shyju 2012-08-03 14:59:03
@Shyju我的班級結構是:公共ID爲Int32,公共名稱爲字符串 – 2012-08-03 15:05:38