首先,我告诉大家,我在google,堆栈溢出和其他论坛中搜索了很多。但没有找到任何解决我的问题的事情。所以最后我在这里把你的问题提交给你的开发人员。
让我们开始:我正在使用linqtosql,web方法和放大器在asp.net 4.0中创建一个Web应用程序。 AJAX。
下面是我的网络方法,它可以正常工作并将数据返回到列表中:
[WebMethod]
public static List<Employee> getEmployee()
{
var db = new BPDataContext();
var elist = db.Employees.ToList(); //getting complete data inside elist successfully
return elist;
}
下面是我的javascript函数,它在jquery document.ready中调用,之后我在getEmployee()函数中创建ajax调用:
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script type="text/javascript">
$(document).ready(function () {
getEmployee();
});
function getEmployee() {
$.ajax({
url: "Emp_Page.aspx/getEmployee",
data: null,
contentType: "Application/json; charset=utf-8",
responseType: "json",
type: "POST",
success: function (response) {
alert(response.d);
},
error: function (xhr) {
alert(xhr.status);
},
Failure: function (response) {
alert(response);
}
});
}
</script>
</script>
</asp:Content>
问题:当页面加载并且alert(xhr.status)
命中并向我显示内部服务器错误500时,但我的Web方法正常工作并检索我在放置断点和检查列表时所需的所有详细信息。在chrome中,当我在错误之前放置断点:function(xhr),在响应文本中它显示我下面的详细错误。
消息“:”序列化类型为\ u0027Adminpanel.Employee \ u0027的对象时检测到循环引用。“,”StackTrace“:”在System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o,StringBuilder sb) ,Int32 depth,Hashtable objectsInUse,SerializationFormat serializationFormat,MemberInfo currentMember)
在System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o,StringBuilder sb,Int32 depth,Hashtable objectsInUse,SerializationFormat serializationFormat,MemberInfo currentMember)
在System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o,StringBuilder sb,Int32 depth,Hashtable objectsInUse,SerializationFormat serializationFormat)
在System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o, StringBuilder sb,Int32 depth,Hashtable objectsInUse,SerializationFormat serializationFormat,MemberInfo currentMember)
在System.Web.Script.Serializ ation.JavaScriptSerializer.SerializeValue(Object o,StringBuilder sb,Int32 depth,Hashtable objectsInUse,SerializationFormat serializationFormat,MemberInfo currentMember)
在System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable enumerable,StringBuilder sb,Int32 depth, Hashtable objectsInUse,SerializationFormat serializationFormat)
在System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o,StringBuilder sb,Int32 depth,Hashtable objectsInUse,SerializationFormat serializationFormat,MemberInfo currentMember)
在System.Web上。 Script.Serialization.JavaScriptSerializer.SerializeValue(Object o,StringBuilder sb,Int32 depth,Hashtable objectsInUse,SerializationFormat serializationFormat,MemberInfo currentMember)
在System.Web.Script.Serialization.JavaScriptSerializer.SerializeCustomObject(Object o,StringBuilder sb,Int32 depth,Hashtable objectsInUse,SerializationFormat serializationFormat)
在System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o,StringBuilder sb,Int32 depth,Hashtable objectsInUse,SerializationFormat serializationFormat,MemberInfo currentMember)
在System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue(Object o ,StringBuilder sb,Int32 depth,Hashtable objectsInUse,SerializationFormat serializationFormat,MemberInfo currentMember)
在System.Web.Script.Serialization.JavaScriptSerializer.SerializeEnumerable(IEnumerable enumerable,StringBuilder sb,Int32 depth,Hashtable objectsInUse,SerializationFormat serializationFormat)
在System.Web.Script.Serialization.JavaScriptSerializer.SerializeValueInternal(Object o,StringBuilder sb,Int32 depth,Hashtable objectsInUse,SerializationFormat serializationFormat,MemberInfo currentMember)
在System.Web.Script.Serialization.JavaScriptSerializer.SerializeValue( Object o,StringBuilder sb,Int32 depth,Hashtable objectsInUse,Serializatio nFormat serializationFormat,MemberInfo currentMember)
在System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj,StringBuilder输出,SerializationFormat serializationFormat)
在System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj,SerializationFormat serializationFormat)
在System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context,WebServiceMethodData methodData,IDictionary`2 rawParams)
在System.Web.Script.Services.RestHandler.ExecuteWebServiceCall( HttpContext context,WebServiceMethodData methodData)“,”ExceptionType“:”System.InvalidOperationException“
现在我完全简单地定义我的问题。请帮帮我。