我正在使用aspx页面中的ajax向c#webmethod发送一些参数。我不得不对注释进行编码并使用替换来删除撇号,因为我找不到以任何其他方式删除撇号的方法。 作为一个实验,我添加了一些字符,如$&%'等,以确保它们正在被处理,它们是。 当把注释带回到gvPSTNResults_RowDataBound()事件中时,我已经编写了一些代码来解码它并且在它返回到gridview之前它似乎没有用。
评论单元格的内容如下所示(在xxx之间应该是& $%之类的字符等),但正如您所看到的那样,它们没有解码:bbbbaaaaa'xxx%40xxx~xxx%24xxx%26xxx%2Cxxx %3Fxx
任何建议都将不胜感激
C#解码从数据库返回的评论:
Label lblComments = new Label();
lblComments = (Label)e.Row.FindControl("lblComments");
string strComments = lblComments.Text;
strComments = System.Net.WebUtility.HtmlDecode(strComments);
lblComments.Text = strComments;
Jquery Ajax:
$("#btnEditFields").click(function () {
var strSupplierOrderNo = $("#<%=tbPopUpEditSuppOrdNo.ClientID%>").val();
var strComment = $("#<%=tbPopUpEditComments.ClientID%>").val();
strComment = encodeURIComponent(strComment);
strComment = strComment.replace(/'/g,"\\'");
var strCurrentStage = $("#<%=ddlPopUpEditCurrentStage.ClientID%>").val();
var strReviewDate = $("#<%=tbPopUpEditReviewDate.ClientID%>").val();
var strOrderDate = $("#<%=tbPopUpEditOrderDate.ClientID%>").val();
var strRequiredLive = $("#<%=tbPopUpEditRequiredLiveDate.ClientID%>").val();
var strActualAppointmentDate = $("#<%=tbPopUpEditActualAppointmentDate.ClientID%>").val();
var strOtherRef = $("#<%=tbPopUpFieldOtherRef.ClientID%>").val();
if (confirm("You are about to add a new comment to order " + strPSTNNum + "?")) {
$.ajax({
type: "POST",
url: "PSTN_OrderManagementTracker.aspx/updatePSTNDataInDB",
data: "{'args':'" +strServiceID+ "', 'args1':'" +strSupplierOrderNo+ "', 'args2':'" +strComment+ "', 'args3':'" +strCurrentStage+ "', 'args4':'" +strReviewDate+ "', 'args5':'" +strOrderDate+ "', 'args6':'" +strRequiredLive+ "', 'args7':'" +strActualAppointmentDate+ "', 'args8':'" +strOtherRef+ "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function () {
alert("Comment successfully added!!!");
location.reload();
},
error: function (xhr, ajaxOptions, thrownError) {
alert(thrownError);
}
});
}
return false;
});
});
答案 0 :(得分:0)
尝试使用Uri.UnescapeDataString()