0
all right?
Next, I’m making a website with navigation on AJAX
, so that it is not necessary to upload the site every time you visit a page. Home, news, contact, etc..
I managed to do the site, update the url, back button, all right..
But I have the following problem
Share/Refresh:
When I refresh the page or try to share the link with someone else, it doesn’t load the site properly. You are opening only the section on that specific page. Ex.: If I want to share the link
site.com.br/sobre.php
it opens only the text of that page. The header, menu, footer do not appear. The css
also comes disfigured.
If it is in the first load of the site, there is no problem.. But if you give refresh or share the link with friend, this problem already happens.
Note: I want to keep this type of navigation by the speed I was able to get on the site.
This is the code I’m using:
$(document).ready(function() {
var content = $('#site'),
firstLink = $(".navbar li:first-child a").attr("href"),
navLink = $(".navbar li a");
content.load(firstLink);
navLink.on("click", function(event){
event.preventDefault();
event.stopImmediatePropagation();
var newLink = $(this).attr("href");
History.pushState(null, null, newLink);
$(".active").removeClass("active");
$(this).addClass("active");
content.load(newLink, function () {
FB.XFBML.parse();
});
});
History.Adapter.bind(window, "statechange", function() {
$(".active").removeClass("active");
$("a[href='" + History.getState().title + "']").addClass("active");
content.load(document.location.href);
});
});
And this is my menu:
<nav class="navbar">
<div class="container">
<ul>
<li><a class="active" href="/content/home.php">Inicio</a></li>
<li><a href="/content/servicos.php">Serviços</a></li>
<li><a href="/content/advogados.php">Advogados</a></li>
<li><a href="/content/escritorio.php">Escritório</a></li>
<li><a href="/content/noticias.php">Notícias</a></li>
<li><a href="/content/contato.php">Contato</a></li>
</ul>
</div>
</nav>
I think that would be it. If anyone can help me, I’d really appreciate it!
@Eirk had already read a little about angular.js, the others I didn’t know. I intend to work more with this teconology because it, unlike php - at least as far as I know, gives much more agility, dynamics and speed to the page. Angular seems to me the most 'known' option, but I did not find a good guide for beginners. Would you have any to recommend? With more time I will look at the other references you have passed. Thank you for now.
– celsomtrindade
@celsomtrindade All these frameworks are relatively new so the frequency of changes is great, because it is very difficult to find quality content in Portuguese. I recommend searching google with date filter last year only. I will edit my reply to add some more alternatives.
– Erik