mardi 5 mai 2015

Title Tag Nested inside itself with jQuery PHP Load

I have a dynamic site that loads only the body when a usr clicks a page. I am trying t change the title tag, but am getting no luck.

HTML:

<head>

    // Title tag is contained in the php file
    <?php include (BASEPATH . "includes/widgets/pageTitle.php"); ?>
</head>

JavaScript/jQuery:

$(document).on('click', 'a', function(e) {

    // Page url of destination
    var pageurl = $(this).attr('href');
    var baseurl = "http://localhost/offstreams/";

    // prevent page from loading
    e.preventDefault();

    // Empty info inside the body class and reload new info
    // THIS WORKS PERFECTLY
    $('.body').empty().load(pageurl + " > .body > *");


    //!!!!!!!!!!!!!!!!!!!!!
    // THIS DOES NOT WORK
    //!!!!!!!!!!!!!!!!!!!!!
    $('title').empty().load(pageurl + "> title > *");


    // Push the URL state
    if(pageurl!=window.location){
        window.history.pushState({path:pageurl},'',pageurl);
    }


    //stop refreshing to the page given in
    return false;
    }
});

A Snippet of PHP code:

//Band page title tag
if (isset($_GET['member']) && isset($_GET['edit']) && isset($_GET['band'])){
    $band_id = $_GET['band'];
    $sql = "SELECT `band_name` FROM `bands` WHERE `band_id` = '$band_id'";
    $query = mysqli_query($conn, $sql);
    while ($row = mysqli_fetch_array($query)){
        $band_name = $row['band_name'];
        echo "<title>" . $band_name . " | " . "Offstreams</title>";
    }

An example output on actual load would be Count to Four | Offstreams, which is what I want.

When I do the ajax load, the website works, but the title tag gives the default url like localhost/offstreams/etc... and the title tag turns into

<title>
    <title>Count to Four | Offstreams</title>
</title>

Does anyone know why?

Aucun commentaire:

Enregistrer un commentaire