【问题标题】:Submission issue internal server error提交问题内部服务器错误
【发布时间】:2016-12-15 06:49:38
【问题描述】:

我正在尝试通过以下表单提交数据,但出现错误:

echo 'The # here does not begin a comment.'
echo The \# here does not begin a comment.

但是如果我们像下面这样提交它不会报错:

echo The # here does not begin a comment.
echo The # here does not begin a comment.

也就是说,没有单引号和斜线,我无法提交数据。

代码如下:

 function AjaxCallOnClick(userName, email, commentText, blogID, commentHtml, onCommentEmailID) {

        var parameters = "{'commentUserName':'" + userName + "','email':'" + email + "','commentText':'" + commentText + "','blogID':'" + blogID + "','commentHtml':'" + commentHtml + "','onCommentEmailID':'" + onCommentEmailID + "'}";
        $.ajax({
            type: "POST",
            url: "<%= ResolveUrl("~/BlogService.asmx/GetShareStoryData")%>",
            data: parameters,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
            alert("Your Comment was Saved");
                var getCommentList = response.d;
                var allComments = '';
                $('#dvMainAndReplyCommentSection').html('');
                $.each(getCommentList, function (index, comments) {
                    var comment = comments.HtmlComment;
                    allComments += comment;
                });
                if (allComments) {
                    $('#dvMainAndReplyCommentSection').html(allComments);
                }

            },
            error: function (jqXHR, textStatus, errorThrown) {

                alert(errorThrown);
            },
            failure: function (response) {
                alert(response.responseText);
            }
        });

    }

解决这个问题的方法是什么?

【问题讨论】:

  • 不需要" " 来定义对象parameters
  • 但是目前用户将这种类型的文本放在字段中,那么正斜杠呢?它也不接受。
  • 你试过下面的代码吗?
  • 我想,你也必须使用JSON.parse()

标签: javascript jquery .net ajax regex


【解决方案1】:

我试过这种格式 var parameters = JSON.stringify({ commentUserName: userName, email: email, commentText: commentText, blogID: blogID, commentHtml: commentHtml, onCommentEmailID: onCommentEmailID });它对我来说很好用。

【讨论】:

    【解决方案2】:

    试一试...保存对象时删除双引号。

    function AjaxCallOnClick(userName, email, commentText, blogID, commentHtml, onCommentEmailID) {
    
    var parameters = JSON.stringify({'commentUserName': userName,'email': email,'commentText': commentText,'blogID': blogID,'commentHtml': commentHtml,'onCommentEmailID': onCommentEmailID});
    
        $.ajax({
            type: "POST",
            url: "<%= ResolveUrl("~/BlogService.asmx/GetShareStoryData")%>",
            data: parameters,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
            alert("Your Comment was Saved");
               var res=JSON.parse(response);
                var getCommentList = res.d;
                var allComments = '';
                $('#dvMainAndReplyCommentSection').html('');
                $.each(getCommentList, function (index, comments) {
                    var comment = comments.HtmlComment;
                    allComments += comment;
                });
                if (allComments) {
                    $('#dvMainAndReplyCommentSection').html(allComments);
                }
    
            },
            error: function (jqXHR, textStatus, errorThrown) {
    
                alert(errorThrown);
            },
            failure: function (response) {
                var res=JSON.parse(response);
                alert(res.responseText);
            }
        });
    
    }
    

    【讨论】:

    • 我尝试了下面的代码,但只有简单的文本,它会引发内部服务器错误。
    • 它不会进入成功部分,然后才需要使用 JSON.parse 函数。但我之前的参数结构简单文本正在工作。
    • 如果您的response 是json 格式,则需要使用JSON.parse()。尝试检查两者。
    • 我不明白你的url。这是什么。
    • 此 url 用作 Web 服务,其中方法是 GetShareStoryData 用于从数据库进行事务。
    猜你喜欢
    • 2018-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多