I have CKEditor & i save that as a Html in my database.Then i'm going to get that saved html stream & show it inside div But it shows the html codes.
My webmethod return below line
<p> <strong>Test Heading </strong></p> <p> <img alt="" src="http://s7.postimg.org/511xwse93/mazda_familia_photo_large.jpg" style="width: 150px; height: 112px;" /></p> <p> test description goes here</p>
Div
<div id="usrnewsdesc"></div>
My Ajax Call
function LoadNewsToUsers() {
debugger;
var newurl = '<%= ResolveUrl("/WebMethods.aspx/GetIndividualUserNews") %>';
$.ajax({
url: newurl,
type: "POST",
data: JSON.stringify({ ToUser: "<%=GetUserID()%>" }),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (Result) {
$.each(Result.d, function (key, value) {
var html ="<body>"+value.News+"</body>";
$("#usrnewsdesc").append(html);
});
},
error: function (e, x) {
alert(x.ResponseText);
}
});
}
My div looks like this
My WebMethod
[WebMethod, ScriptMethod]
public static List<UserNews> GetIndividualUserNews(Guid ToUser)
{
List<UserNews> UserNewsDetails = new List<UserNews>();
try
{
SqlCommand comGetAllFiles = new SqlCommand("SP_GetNewsToUser", conDB);
comGetAllFiles.CommandType = CommandType.StoredProcedure;
if (conDB.State == ConnectionState.Closed)
conDB.Open();
comGetAllFiles.Parameters.Add("@ToUser", SqlDbType.UniqueIdentifier);
comGetAllFiles.Parameters["@ToUser"].Value = ToUser;
SqlDataReader rdr = comGetAllFiles.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(rdr);
foreach (DataRow r in dt.Rows)
{
UserNewsDetails.Add(new UserNews
{
Id = (int)r["Id"],
News = r["News"].ToString(),
DateTime =(DateTime) r["DateTime"],
ToUser = (Guid)r["ToUser"]
});
}
}
catch (Exception ee)
{
}
finally
{
conDB.Close();
}
return UserNewsDetails;
}
Console.log is below
<p>
<strong>Test Heading </strong></p>
<p>
<img alt="" src="http://s7.postimg.org/511xwse93/mazda_familia_photo_large.jpg" style="width: 150px; height: 112px;" /></p>
<p>
test description goes here</p>
Test Heading
test description goes here
– TechGuy May 02 '14 at 18:25