아래 코드에 무엇이 잘못 되었나요? 왜 작동하지 않는지 알려주세요.Jquery.ajax를 사용하여 <> 목록을 가져올 수 없습니다.
aspx.cs 페이지의 webmethod. 내가 응용 프로그램 아무 일도 실행할 때 아래
[webmethod]
[ScriptMethod(ResponseFormat=ResponseFormat.Json)]
public static List<Problem> GetProblems()
{
List<Problem> allproblems = new List<Problem>();
using (TMEntities tm = new TMEntities())
{
allproblems = tm.Problems.ToList();
}
return allproblems;
}
및 HTML
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type:"POST",
url: "WebForm1.aspx/GetProblems",
data: "{}",
datatype: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
alert('success');
},
failure: function (response) {
alert("fail");
}
});
});
</script>
내가 오류 아래 브라우저에서 오류를 확인하려면 Ctrl + Shift + J를 누르면는
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
ajax URL의 페이지 메서드로 어떻게 리디렉션 할 것으로 예상합니까? 오른쪽 WebForm1.aspx? GetProblems = true이면 Response 매개 변수 GetProblems에 대한 page_load가 true인지 확인합니다. GetProblems가 true 인 경우 GetProblems입니다. – mybirthname
'GetProblems' 메소드를 디버깅 할 때 무엇이 보입니까? (시작시 중단 점을 설정 한 다음 디버거에서 웹 응용 프로그램을 실행하십시오.) – Richard
로컬에서 실행 중이므로 디버그 (클라이언트) 도구에서 네트워크 탭을 클릭하고 500 오류 URL을 확인하십시오. 서버가 500을 리턴하는 정확한 오류. 이유가있을 수 있으며 일부 DLL이 누락되었거나 다른 것일 수 있습니다. 따라서 클라이언트 디버그 도구가 이유를 제공합니다. 응용 프로그램을 DEBUG 모드로 실행하여 어쨌든 수행해야합니다. – codebased