New to jQuery and Have a Problem
I'm working on reviving a project and currently the project uses jQuery 1.6.2 and works fine with it however as part of the revival, it needs to be upgraded so we can take advantage of newer technologies, etc.
When I replace jQuery 1.6.2 with 1.9.1, the script fails to load any data and returns this error in Firebug
Error: Syntax error, unrecognized expression: a[href="#home"],
On the HTML page, I have this code currently:
- jQuery(document).ready(function() {
- function request(page) {
- jQuery('#content').html('<h2 class="mainHeading">Loading</h2><p>Requesting content from server, please wait.</p>');
- jQuery.ajax({
- url: 'index.php',
- type: "GET",
- data: "page=" + page,
- timeout: 15000
- })
- .error(function(xhr, status) {
- var errorMsg = '<p>Error loading the page!</p>';
- if(null != status) {
- errorMsg = 'Sorry, but "' + status + '" occured!';
- }
- jQuery('#content').html('<h2 class="mainHeading">Error</h2>' + errorMsg);
- })
- .success(function(data) {
- jQuery('<?php echo genNav(); ?>').removeClass('active');
- jQuery('a[href="#' + data.pageName + '"]').addClass('active');
- jQuery('#content').html(data.content);
- });
- }
- jQuery('<?php echo genNav(); ?>').click(function(e) {
- e.preventDefault();
- var pageName = jQuery(this).attr('href').split("#")[1];
- request(pageName);
- });
- request('home');
- });
And the genNav function is here:
- function genNav() {
- if ($handle = opendir('tpl')) {
- while (false !== ($file = readdir($handle))) {
- if ($file != "." && $file != "..") {
- $file = substr($file, 0, -(strlen($file)-(strrpos($file, "."))));
- if ($file == "wsl"){ } else {
- echo "a[href=\"#$file\"],";
- }
- }
- }
- closedir($handle);
- }
- }
What's the problem here? Could someone please help me make sense of
what the issue is and how I could resolve this? Thank you!