【发布时间】: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