AJAX Code Review
AJAX Code Review
I wrote my first AJAX script that brings content from other pages without refreshing the entire page and i just want to see if improvements can be added to it, or if im doing something not recommended. Thank you.
- $(function(){
- // content container content loader
- $("#nav-tabs-list a").click(function() {
- var page = this.hash.substr(1);
- //$("#sidebar-content-container").html(""); // displays content only after fully loaded
- $.get("content/" + page + ".php", function(gotHtml) {
- $("#content-container").html(gotHtml);
- });
- });
- if ( location.hash ) {
- $("a[href="+location.hash+"]").click();
- } else {
- $("#nav-tabs-list a").click();
- }
- // sidebar content loader
- $("#sidebar-container #sidebar-tabs-container a").click(function() {
- var page = this.hash.substr(1);
- //$("#sidebar-content-container").html(""); // displays content only after fully loaded
- $.get("content/sidebar-content/" + page + ".php", function(gotHtml) {
- $("#sidebar-content-container").html(gotHtml);
- });
- });
- if ( location.hash ) {
- $("a[href="+location.hash+"]").click();
- } else {
- $("#sidebar-container #sidebar-tabs-container a").click();
- }
- });