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.



  1. $(function(){

  2. // content container content loader
  3. $("#nav-tabs-list a").click(function() {
  4. var page = this.hash.substr(1);
  5. //$("#sidebar-content-container").html(""); // displays content only after fully loaded
  6. $.get("content/" + page + ".php", function(gotHtml) {
  7. $("#content-container").html(gotHtml);
  8. });
  9. });
  10. if ( location.hash ) {
  11. $("a[href="+location.hash+"]").click();
  12. } else {
  13. $("#nav-tabs-list a").click();
  14. }


  15. // sidebar content loader
  16. $("#sidebar-container #sidebar-tabs-container a").click(function() {
  17. var page = this.hash.substr(1);
  18. //$("#sidebar-content-container").html(""); // displays content only after fully loaded
  19. $.get("content/sidebar-content/" + page + ".php", function(gotHtml) {
  20. $("#sidebar-content-container").html(gotHtml);
  21. });
  22. });
  23. if ( location.hash ) {
  24. $("a[href="+location.hash+"]").click();
  25. } else {
  26. $("#sidebar-container #sidebar-tabs-container a").click();
  27. }






  28. });