A simple question for a coder well versed in JS.
I am creating a Wordpress site that uses JQuery AJAX methods, reloading either my entire content area when the top navigation link is clicked, or my main content area when the navigation bar link is clicked. I want to be sure that an AJAX call is only issued if the user's browser supports JavaScript. I found some reference materials here and on other sites, which, referring to the appearance of the script from the outside, a browser that is not equipped with JavaScript, simply ignores all JS files. That's for sure? I reviewed using php:
$my_arr = get_browser(null,true);if $my_arr['javascript'] == 1 { echo '<script type="text/javascript" src="path/to/script"'; }
The UX I'm going for is if JS is enabled, then start AJAX calls; if JS is disabled, just send the user to the requested page.
eg.
<?php /** * The template for displaying all pages. * $ajxy = $_GET['ajxy']; if(!is_null($ajxy)) { $ajax_code = $ajxy; } if(!$ajxy) { get_header(); } ?> <?php if(!$ajax_code) { ?> <div id="primary"> <div id="content" role="main"> <div class="container_12" id="contentWrapper"> <?php } ?> <div id="contentContainer" <?php if($ajax_code) { echo 'class="ajxn"'; } ?>> <?php while ( have_posts() ) : the_post(); ?> <div class="grid_8" id="contentGrid"> <?php get_template_part( 'content', 'page' ); ?> </div> <?php get_sidebar(); ?> <?php endwhile; // end of the loop. ?> </div> <?php if(!$ajax_code) { ?> </div> </div><!--
and script:
function ajxnOff(list, ajxnCode, wrapper, container) { jQuery(list).click(function(e) { e.preventDefault(); var $lnkGoz = jQuery(this).attr("href"); var $lnkGozAjx = $lnkGoz + '?ajxy=' + ajxnCode; var $ajxyContainer = wrapper; var $ajxyCurThing = container; $ajxyCurThing.fadeOut(400, function() { $ajxyContainer.html('<div id="loaderA"></div>'); jQuery("div#loaderA").fadeIn(400); jQuery.ajax({ url: $lnkGozAjx, success: function(data) { jQuery("div#loaderA").delay(2000).fadeOut(400, function() { $ajxyContainer.html(data); jQuery("div.ajxn").fadeIn(400); jQuery.remove("div#loaderA"); }); } }); }); }); } jQuery(document).ready(function() { ajxnOff(jQuery("ul#topNavList a"), 1, jQuery("div#contentWrapper"), jQuery("div#contentContainer")); ajxnOff(jQuery("ul#sidebarNavList a"), 2, jQuery("div#contentGrid"), jQuery("div#contentPageContainer")) });
I learned to program on my own for about 6 months and do not have books on this issue, so any help from experts is very much appreciated here.