I am creating comment system in ASP.Net through jQuery AJAX but I am facing a problem of loading images from the database. I have 3 tables in the database:
- UserRegistration(uid(PK),username....)
- Profile(profileID(PK),uid(FK),fulname,userPic...)
- Comment(cmntID(PK),cmntText,uid(FK)....)
The following is the jQuery AJAX code:
function getcomment() {
var postPlace = $('div.q1');
$.ajax({
url: '/WebForm1.aspx/GetComment',
contentType: "application/json; charset=utf-8",
data: "{}",
dataType: 'json',
type: 'POST',
success: function (data) {
var newData = jQuery.parseJSON(data.d);
var trHtml = '';
var loadPost = postPlace;
$.each(newData, function (i, item) {
trHtml += '<div class="q2" style="background-color: red">' +
'<img src="' + item.userPic + '" class="img-circle" width="32px" height="32px" />'+
'<span>' + item.username + '</span>' +
'<p>' + item.cmntText + '</p>' + '</div>';
});
loadPost.html(trHtml);
}
Here is the problem with item.userPic which is inside the loop. item.username and item.cmntText works well but item.userPic is not working. However when i access another attribute of the Profile table like fulname then it works. I just can't access userPic of the same table.
This is the code behind in C#:
[WebMethod]
public static string GetComment()
{
string connection = ConfigurationManager.ConnectionStrings["connection"].ConnectionString;
SqlConnection con = new SqlConnection(connection);
SqlDataAdapter da = new SqlDataAdapter("select * from userregistration inner join comment on userregistration.uid=comment.uid inner join profile on comment.uid=profile.uid order by cmntID DESC ", con);
DataTable dt = new DataTable();
da.Fill(dt);
return JsonConvert.SerializeObject(dt);
}
This is the result that I get:

console.log(item.userPic)log atconsole?