javascript - ajax发布错误: internal error 500 on post method

标签 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

最佳答案

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

关于javascript - ajax发布错误: internal error 500 on post method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25886468/

相关文章:

javascript - jQuery 漂亮的照片插件不会在图库中显示缩略图

javascript - 使用 Select2 小部件时检索选项名称而不是本地存储 JavaScript 中的值

javascript - 如何在 API 调用的 header 中包含 AuthToken?

c# - 两个更新面板

asp.net - div继承父级不透明度

javascript - 使用子元素的 id 为父级绑定(bind)点击事件

javascript - 每次测试前在 mocha 套件中设置变量?

javascript - 在 HTML5 中设置透明颜色

php - Onsubmit javascript 将值发送到 php 并返回值

javascript onclick滚动到中间页面上的div?