小编Mr.*_*ost的帖子

使用Jquery Ajax将html字符串传递给服务器端

我在这个网站上看到很多答案对我有很大的帮助但是在这个问题上我需要请大家帮助我.

我有一个textarea作为Html编辑器将html内容传递给服务器并将其附加到新创建的Html页面(用于用户POST等),但jquery或ASP.NET不接受jquery通过数据传递的Html内容: {}

- 对于Jquery:

  $("#btnC").click(function (e) {
    e.preventDefault();

    //get the content of the div box 
    var HTML = $("#t").val();

    $.ajax({ url: "EditingTextarea.aspx/GetValue",
        type: "POST",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        data: '{num: "' + HTML + '"}', // pass that text to the server as a correct JSON String
        success: function (msg) { alert(msg.d); },
        error: function (type) { alert("ERROR!!" + type.responseText); }

    });
Run Code Online (Sandbox Code Playgroud)

和服务器端ASP.NET:

[WebMethod]
public static string GetValue(string num)
{ 
    StreamWriter sw = new StreamWriter("C://HTMLTemplate1.html", true);
    sw.WriteLine(num);
    sw.Close(); …
Run Code Online (Sandbox Code Playgroud)

c# asp.net ajax jquery

5
推荐指数
2
解决办法
3万
查看次数

标签 统计

ajax ×1

asp.net ×1

c# ×1

jquery ×1