Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/450.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将html标记传递给webmethod?_Javascript_Jquery_Asp.net_Html - Fatal编程技术网

Javascript 如何将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 =

我试图将包含html标记的参数作为其值传递给webmethod。但它似乎不起作用,我只是得到了错误。这样做可能吗。你能建议其他方法做同样的事情吗

 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编码吗?你的意思是要转换所有那些<>符号吗?不