Скажем ответ от ajaxa:
content = '<p><a href="#" data-id="'+value['post_id']+'" class="btn btn-primary read-more" role="button">Read more</a></p>'
$('section').append(content);
и скажем после
$('.read-more').click(function(){
alert('ok');
});
то нифига не алертит(
//
Код целиком:
При клике по определенной категории, выводятся посты:
$('.cat').click(function () {
data = {id: $('a', this).data('id')};
$.ajax({
url: base_url + 'getContentByCategory',
method: 'POST',
data: data,
success: function (response) {
$('section').html('');
obj= JSON.parse(response);
$.each(obj, function(key, value){
content = '<div class="row">' +
'<div class="col-sm-6 col-md-4">' +
'<div class="thumbnail">' +
'<div class="caption">' +
'<h3>'+value["tittle"]+'</h3>' +
'<p>'+value["content"]+'</p>' +
'<p class="read-more"><a href="#" data-id="'+value['post_id']+'" class="btn btn-primary" role="button">Read more</a></p>' +
'</div></div></div></div>';
$('section').append(content);
});
}
})
});
После чего при нажатии кнопки read more, хочу чтобы открывался один пост, на тот который выбрали:
$('.read-more').click(function(){
alert('ok');
data={post_id:$('a', this).data('id')};
$.ajax({
url: base_url + 'getSinglePost',
method: 'POST',
data: data,
success: function (response) {
$('section').html('');
obj= JSON.parse(response);
$.each(obj, function(key, value){
console.log(value);
content= '<div class="page-header">'+
'<h1>'+value['tittle']+'</h1>'+
'</div>'+
'<p>'+value['content']+'</p>';
$('section').append(content);
})
}
});
});