Javascript ajax post错误:post方法内部错误500

Javascript ajax post错误:post方法内部错误500,javascript,jquery,ajax,vb.net,Javascript,Jquery,Ajax,Vb.net,我正在运行下面的脚本,当计时器超时时,当我开始传递最终信息保存所需的数据时,帖子工作正常。当你有内部错误的时候 JavaScript ajax调用 Vb.net代码。 <WebMethod()> Public Shared Function timeFinished(questNo As String, selectedoption As String) As String Dim objExam As New examClass() If s

我正在运行下面的脚本,当计时器超时时,当我开始传递最终信息保存所需的数据时,帖子工作正常。当你有内部错误的时候

JavaScript ajax调用

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

公共共享函数timeFinished(questNo作为字符串,selectedoption作为字符串)作为字符串
Dim objExam作为新的examClass()
如果选择选项=“-1”,则
'lblWarning.Visible=True
'lblWarning.Text=“请回答问题!”
其他的
'lblMessage.Text=“Navigation=“&Request.Form”(“textNav”)
objExam.answerQuestion(HttpContext.Current.Session(“examid”),任务号,选择选项,“00:00:00”)
'lblWarning.Visible=False
"密切联系",
objExam.Dispose()
如果结束
finishTest(Convert.ToInt32(HttpContext.Current.Session(“examid”).ToString())
objExam.Dispose()
'HttpContext.Current.Response.Redirect(“ChapterTestSummary.aspx”,true);
Dim url为String=“testsummary.aspx”
返回url
端函数

我认为问题在于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;
    }
});

完美答案。我所要做的就是找到一个职位
$.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;
    }
});