提交问题内部服务器错误

时间:2016-12-15 06:49:39

标签: javascript jquery .net ajax regex

我正在尝试通过下面的表单提交数据,这会产生错误:

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);
            }
        });

    }

这方面的工作是什么?

2 个答案:

答案 0 :(得分:1)

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

答案 1 :(得分:0)

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

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);
        }
    });

}