2014-09-17 4 views
0

나는 아래의 스크립트를 실행하고 있는데, 타이머가 만료 된 후, 최종 정보가 저장 될 필요가있는 데이터를 전달하기 시작할 때 게시물이 제대로 작동하고있었습니다. 그 때 내부 오류가 발생했습니다.아약스 게시 오류 : 게시물 오류시 내부 오류 500

자바 스크립트 아약스 호출

var selectedval; 
      if (document.getElementById('RadioButtonList1_0').checked == true) { 
       selectedval = document.getElementById('RadioButtonList1_0').value 
      } 
      else if (document.getElementById('RadioButtonList1_1').checked == true) { 
       selectedval = document.getElementById('RadioButtonList1_1').value 
      } 
      else if (document.getElementById('RadioButtonList1_1').checked == true) { 
       selectedval = document.getElementById('RadioButtonList1_1').value 
      } 
      else if (document.getElementById('RadioButtonList1_2').checked == true) { 
       selectedval = document.getElementById('RadioButtonList1_2').value 
      } 
      else if (document.getElementById('RadioButtonList1_3').checked == true) { 
       selectedval = document.getElementById('RadioButtonList1_3').value 
      } 
      else { 
       selectedval = ''; 
      } 
      var qustNo = document.getElementById('ltlQuestNos').innerHTML; 


`enter code here`   $.ajax({ 
       type: "GET", 
       data: '{questNo:'+ qustNo.trim().toString()+',selectedoption:'+ selectedval.toString()+'}', 
       contentType: "application/json; charset=utf-8", 
       url: "prTest.aspx/timeFinished", 
       dataType: "json", 
       success: function (result) { 
        // this displays the information so that the page can be re-directed to the results page. 
        window.location = result.d; 
       } 

Vb.net 코드입니다.

<WebMethod()> 
    Public Shared Function timeFinished(questNo As String, selectedoption As String) As String 
     Dim objExam As New examClass() 
     If selectedoption = "-1" Then 
      'lblWarning.Visible = True 
      'lblWarning.Text = "Please answer Question!" 
     Else 
      ' lblMessage.Text = "Navigation = " & Request.Form("textNav") 
      objExam.answerQuestion(HttpContext.Current.Session("examid"), questNo, selectedoption, "00:00:00") 
      ' lblWarning.Visible = False 
      'close connection 
      objExam.Dispose() 
     End If 
     objExam.finishTest(Convert.ToInt32(HttpContext.Current.Session("examid").ToString())) 
     objExam.Dispose() 
     ' HttpContext.Current.Response.Redirect("ChapterTestSummary.aspx", true); 

     Dim url As String = "testsummary.aspx" 
     Return url 
    End Function 

답변

1

나는 문제가 아약스의 데이터 부분이라고 생각합니다. 왜냐하면 만약 당신이 스스로 데이터를 문자열로 작성한다면, 키와 값은 큰 따옴표로 묶어야합니다. 그렇지 않으면 객체로 만들고 JSON.stringify() 메서드를 사용하여 문자열로 만듭니다.

$.ajax({ 
    type: "GET", 
    data: JSON.stringify({ 
     questNo: qustNo.trim(), 
     selectedoption: selectedval 
    }), 
    contentType: "application/json; charset=utf-8", 
    url: "prTest.aspx/timeFinished", 
    dataType: "json", 
    success: function(result) { 
     // this displays the information so that the page can be re-directed to the results page. 
     window.location = result.d; 
    } 
}); 
+1

완벽한 답변 나는해야만했다. – user3086751