I am working on a piece of code to load part of my content dynamically after user triggers the event by clicking. the code works when i'm using static pages but loading dynamically generated page blank.
Case Scenario is: when user clicks on the post, it will open a modal
and display the detailed view which is the dynamic generated content using the slug
in the link.
here is my code.
PHP (Laravel) and HTML snippet ():
updated
<div class="content-blocks blog hidex">
<section class="content">
<div class="block-content">
<h3 class="block-title">My Blog</h3>
<div id="post-list" class="col-md-10 col-md-offset-1">
{% set posts = blogPosts.posts %}
{% for post in posts %}
<div class="post">
<div class="post-thumbnail">
{% if post.featured_images.count %}
{% set image = post.featured_images|first %}
<a class="open-post" href="{{'blog-post'|page}}">
<img
data-src="{{ image.filename }}"
src="{{ image.path }}"
alt="{{ image.description }}"
style="max-width: 100%"/>
</a>
{% endif %}
</div>
<div class="post-title">
<a class="open-post" href="{{ post.url }}"><h2>{{ post.title }}</h2></a>
<p class="post-info">
<span class="post-author">Posted by {{ post.user.first_name}} </span>
<span class="slash"></span>
<span class="post-date">on {{ post.published_at|date('M d, Y') }}</span>
<span class="slash"></span>
{% if post.categories.count %} in {% endif %}
{% for category in post.categories %}
<span class="post-category">{{ category.name }}</span>
{% if not loop.last %}, {% endif %}
{% endfor %}
</p>
</div>
<div class="post-body">
<p>{{ post.summary }}</p>
<a class="btn open-post" href="{{ post.url }}">Read More</a>
</div>
</div>
{% endfor %}
<div class="text-center">
{% if posts.lastPage > 1 %}
<ul class="pagination">
{% if posts.currentPage > 1 %}
<li>
<a href="{{ this.page.baseFileName|page({ (pageParam): (posts.currentPage-1) }) }}"
aria-label="Previous">
<span aria-hidden="true">«</span>
</a></li>
{% endif %}
{% for page in 1..posts.lastPage %}
<li class="{{ posts.currentPage == page ? 'active' : null }}">
<a href="{{ this.page.baseFileName|page({ (pageParam): page }) }}">{{ page }}</a>
</li>
{% endfor %}
{% if posts.lastPage > posts.currentPage %}
<li><a href="{{ this.page.baseFileName|page({ (pageParam): (posts.currentPage+1) }) }}"
aria-label="Next">
<span aria-hidden="true">»</span>
</a>
</li>
{% endif %}
</ul>
{% endif %}
</div>
</div>
</div>
</section>
</div>
JavaScript updated:
$('#post-list').on('click','a', function(){
var postUrl = $(this).attr("href");
var post = '<div class="modal" id="post-modal"><div class="inline-menu-container"><a id="modal-close" class="close" data-dismiss="modal"><span aria-hidden="true">×</span></a></div><div class="modal-dialog"><div class="modal-content"></div></div></div>';
$(post).modal({
remote: postUrl + ' #post'
})
return false;
});
result adds only this code to the DOM without the dynamic content from the post link:
<div class="stripe-loading-indicator loaded"><div class="stripe"></div><div class="stripe-loaded"></div></div>
<div class="modal-backdrop in"></div>
<div class="modal in" id="post-modal" style="display: block;"><div class="inline-menu-container"><a id="modal-close" class="close" data-dismiss="modal"><span aria-hidden="true">×</span></a></div><div class="modal-dialog"><div class="modal-content"></div></div></div>
Expected result is to add the following code to the DOM:
<div class="stripe-loading-indicator loaded"><div class="stripe"></div><div class="stripe-loaded"></div></div>
<div class="modal-backdrop in"></div>
<div class="modal-dialog"><div class="modal-content"><div id="post" class="blog">
<section id="layout-content">
<div class="content"><p>This is your first ever <strong>blog post</strong>! It might be a good idea to update this post with some more relevant content.</p>
<p>You can edit this content by selecting <strong>Blog</strong> from the administration back-end menu.</p>
<p><em>Enjoy the good times!</em></p></div>
<div class="featured-images text-center">
<p>
<img
data-src="PhenometechBusiness-Card-Back.jpg"
src="/storage/app/uploads/public/587/d0a/0e0/587d0a0e0608e385456109.jpg"
alt=""
style="max-width: 100%" />
</p>
</div>
<p class="info">
Posted
in
<a href="http://localhost:8000/blog">generic</a> on Jan 16, 2017
</p>
</div>
</section>
</div>
</div>
</div>
*note: I have read similar questions posted, but none of the solutions worked for me so far.