Reputation: 543
When I click on the first link pjax fires with the correct content. However, when I select the second link pjax adds to the alread select link like this "http://localhost.com/name/test1/name/test2/" then returns to the index page. I am guessing because of the addition of the second link. How do I resolve this problem?
<li><a data-pjax='#content' href="name/test1/"> test1 </a></li>
<li><a data-pjax='#content' href="name/test2/"> test2</a></li>
<li><a data-pjax='#content' href="name/test3/"> test3 </a></li>
<script type="text/javascript">
$(document).ready(function(){
$(function(){
$('a[data-pjax]').pjax({container:'#content',timeout:15000});
});
});
</script>
Upvotes: 0
Views: 348
Reputation: 71
Probably because you are using relative path in the links, try changing it to:
<li><a data-pjax='#content' href="/name/test1/"> test1 </a></li>
<li><a data-pjax='#content' href="/name/test2/"> test2</a></li>
<li><a data-pjax='#content' href="/name/test3/"> test3 </a></li>
By adding /
at the beginning of your href
attributes.
Assuming you started at /
, when you click on the first link, pjax changes the page location windows.location
to /name/test1/
. A link to name/test2/
on page /name/test1/
means /name/test1/
+ name/test2/
=> /name/test1/name/test2/
, since it is a relative path.
Upvotes: 1