Good day. I faced a problem and due to lack of knowledge I cannot solve it myself, therefore I am asking you for help.

Essence: It is necessary to click on the button, show the block element and load the content there in the form of html tables.

$("#ref-show").click(function (e) { e.preventDefault(); $.ajax({ url: "Test.aspx/GetTable", type: "POST", dataType: "html", success: function (data) { $("#ref-content").html(data); } }); return false; }); 

on server:

  [WebMethod] public static Table GetTable() { Table result = new Table(); // формируем таблицу и заполняем данными из SQL return result; } 

The table is filled with data from the SQL database. Moreover, if I put contentType: "application / json; charset = utf-8", then the GetTable () procedure works (I see the SQL query with the trace), if I don’t specify the contentType, then the whole page is loaded without the table I need and the SQL query does not work. I’m apparently dumbing somewhere, point me to my mistake.

    1 answer 1

    It turned out this way:

     $("#ref-show").click(function (e) { e.preventDefault(); $.ajax({ url: "Test.aspx/GetTable", type: "POST", contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { $("#ref-content").html(data.d); } }); return false; 

    });

    From the server, return the line:

      [WebMethod] public static string GetTable() { Table result = new Table(); // Формирую html таблицу result = Provider.CreateHtmlDataTable(); StringWriter sw = new StringWriter(); result.RenderControl(new HtmlTextWriter(sw)); return sw.ToString(); } 

    Maybe someone will come in handy.