Javascript 如何将html标记传递给webmethod?
我试图将包含html标记的参数作为其值传递给webmethod。但它似乎不起作用,我只是得到了错误。这样做可能吗。你能建议其他方法做同样的事情吗Javascript 如何将html标记传递给webmethod?,javascript,jquery,asp.net,html,Javascript,Jquery,Asp.net,Html,我试图将包含html标记的参数作为其值传递给webmethod。但它似乎不起作用,我只是得到了错误。这样做可能吗。你能建议其他方法做同样的事情吗 htmlContent = htmlContent + document.getElementById("divFollowsTestDiv").innerHTML; function StoreSessionForHtml(htmlContent) { var requesthtmlContentParameter =
htmlContent = htmlContent + document.getElementById("divFollowsTestDiv").innerHTML;
function StoreSessionForHtml(htmlContent) {
var requesthtmlContentParameter = '{' +
'htmlContent:"' + htmlContent + '"}';
$.ajax({
type: "POST",
url: "Webtop.aspx/HTMLTableContent",
data: requesthtmlContentParameter,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert("Success", msg.d);
}, //Event that'll be fired on Success
error: function() {
alert("Try Again");
} //Event that'll be fired on Error
});
}
//这里我存储标签,下面的方法调用webmethod
function StoreSessionForHtml(htmlContent) {
var requesthtmlContentParameter = '{' +
'htmlContent:"' + htmlContent + '"}';
$.ajax({
type: "POST",
url: "Webtop.aspx/HTMLTableContent",
data: requesthtmlContentParameter,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert("Success", msg.d);
}, //Event that'll be fired on Success
error: function() {
alert("Try Again");
} //Event that'll be fired on Error
});
}
您应该在客户端进行URL编码,在客户端进行解码。本质上它改变了也许一个更稳定、更安全的解决方案是在数据发送之前将其建立在基础64上? Base 64将整个字符串转换为一组严格的a-zA-Z0-9和等号。 在ASP中,您可以使用以下命令创建base64:
function StoreSessionForHtml(htmlContent) {
var requesthtmlContentParameter = '{' +
'htmlContent:"' + htmlContent + '"}';
$.ajax({
type: "POST",
url: "Webtop.aspx/HTMLTableContent",
data: requesthtmlContentParameter,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert("Success", msg.d);
}, //Event that'll be fired on Success
error: function() {
alert("Try Again");
} //Event that'll be fired on Error
});
}
你试过用html编码吗?你的意思是要转换所有那些<>符号吗?不