如何将html标记传递给网络方法? [英] How to pass html tags to a webmethod?
问题描述
我正在尝试将包含html标记的参数作为其值传递给webmethod.但它似乎无法正常工作,我只收到错误消息.有可能这样做吗?您能提出其他建议吗?
I'm trying to pass a parameter containing html tags as its value to a webmethod. But it seems not working and i'm only getting the error. Is that possible to do so. Can you suggest any other way to do the same.
htmlContent = htmlContent + document.getElementById("divFollowsTestDiv").innerHTML;
///在这里,我存储标签,并且以下方法调用了web方法.
// Here im storing the tags and the following method calls the 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
});
}
推荐答案
也许更稳定,更安全的解决方案是在发送数据之前对数据进行base64处理? 基数64会将整个字符串转换为严格的a-zA-Z0-9和等号. 在ASP中,您可以使用以下代码进行base64: http://www.freevbcode.com/ShowCode.asp ?ID = 5248
Perhaps a more stable and safer solution would be to base64 the data before it is sent? Base 64 will convert the entire string to a strict set of a-zA-Z0-9 and an equals sign. In ASP you can base64 using this: http://www.freevbcode.com/ShowCode.asp?ID=5248
// This code was written by Tyler Akins and has been placed in the
// public domain. It would be nice if you left this header intact.
// Base64 code from Tyler Akins -- http://rumkin.com
var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function encode64(input) {
var output = new StringMaker();
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output.append(keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4));
}
return output.toString();
}
这篇关于如何将html标记传递给网络方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!