Hello.
I'm trying to make tabs on Ajax. Everything works, but there are a couple of questions. Here is the markup
<ul> <li class="active"><a href="/post/{{ $post->slug }}" data-ajax-tab>Рекомендуемые</a></li> <li><a href="/post/{{ $post->slug }}/most-viewed" data-ajax-tab>Самые просматриваемые</a></li> <li><a href="/post/{{ $post->slug }}/popular" data-ajax-tab>Популярные<span>(0)</span></a></li> </ul> Here is the script itself
var ajaxLoader = $('[data-loader]'); $('[data-ajax-tab]').on('click', function(e){ e.preventDefault(); var link = $(this); var url = link.attr('href'); $('li.active').removeClass('active'); link.parent().addClass('active'); var contentArea = $('[data-post-content]'); contentArea.empty(); ajaxLoader.show(); setTimeout(function(){ $.get({ url: url, dataType: "html", success: function(template) { contentArea.append(template); ajaxLoader.hide() }, error: function(error) { } }) }, 2000); }); Now, if you go to the address site.name/post/bla-bla/popular , then the template is given, which, when you click on the tab популярные is given популярные . And how to make that the page would be loaded, and automatically the tab популярные became active?
And the second question, why query string does not change? I'm getting a het method. Tab is activated, and the address remains unchanged.
site.name/post/perviy-probniy-postpage. Then, under the post, I press on theпопулярныеtab. This tab has an address of the formsite.name/post/perviy-probniy-post/popular, the tab is activated, popular posts appear. But the address of the site issite.name/post/perviy-probniy-post, why not `` site.name / post / perviy-probniy-post / popular`? I after all use $ .get ({}). Should he vedt go to this address? - Alex_01