ajax发布错误:post方法的内部错误500

时间:2014-09-17 09:09:13

标签: javascript jquery ajax vb.net

我正在运行下面的脚本,当计时器已用完时,当我开始传递数据时,帖子工作正常,需要保存最终信息。当出现内部错误时

JavaScript ajax调用

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 个答案:

答案 0 :(得分:1)

我认为问题在于ajax中的数据部分。因为,如果您自己将数据构建为字符串,则键和值应用双引号括起来。否则将其作为对象并使用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;
    }
});