Simple implementation of adding Html text content to div with jQuery

  • 2021-07-04 17:39:45
  • OfStack

Foreground code:


<link href="https://www.ofstack.com/Content/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" />
<script src="https://www.ofstack.com/Scripts/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="https://www.ofstack.com/Scripts/jquery-ui.js" type="text/javascript"></script>

function PoeviewExcel() {
  $.ajax(
  {
   url: "send/index",
   type: "post",
   success: function (data) {
    var divshow = $("#showInfo2");
    divshow.text("");//  Empty data 
    divshow.append(data); //  Add Html Content, cannot be used Text  Or  Val
    divshow.dialog({
     title: " SMS Group Sending System ",
     height: 250,
     width: 580
    });

   }
  }
  );
  return false;
 }

<a href="#" onclick="return PoeviewExcel()"> Preview data </a> 
<div id="divPreview" style="display: none">  
<text id="showInfo2"></text> 
</div>

Backstage (main):


public string GetImportReport()
  {
   DataTable dt = this.ImportExcel();
   string content = String.Empty;
   content = @"<table width='550' border='0' cellspacing='0' cellpadding='0' bgcolor='#D2D2D2'>"
     + " <tr bgcolor='#336699'>"
     + " <td align='center'><strong> Serial number </strong></td>"
     + " <td align='center'><strong> Target mobile phone number </strong></td>"
     + " <td align='center'><strong> Send content </strong></td>"
     +"</tr>";
   for (int i = 0; i < dt.Rows.Count; i++)
   {
    content += "<tr>"
     + " <td width='50' align='center'>" + i.ToString()+"</td>"
     + " <td width='150' align='center'>" + dt.Rows[i][0].ToString() + "</td>"
     + " <td width='150' >" + dt.Rows[i][1].ToString() + "</td>"
     + " </tr>";
   }
   content += "</table>";
   return content;
  }

Description:

divshow. append (data); //Add Html content, not Text or Val

Use after (), of course; Information is continuously appended to the div.

If Text is used: display the loaded text content;

If you use Val: Click the link for the first time to empty the window, and then click again to display the data.


Related articles: