神秘的“1”;出现在加载内容的末尾

mysterious "1" appearing at end of loaded content

本文关键字:加载      更新时间:2023-09-26

我得到一个非常恼人和神秘的"1"显示在每个页面的右下角,从我假设是一个错误的地方在以下ajax请求和php代码。标记为php loader的部分是同名的单独页面。HTML是li's带散列标签和rel="ajax"

$(document).ready(function () {

        //Check if url hash value exists (for bookmark)
    $.history.init(pageload);   
        //highlight the selected link
    $('a[href=' + document.location.hash + ']').addClass('selected');
        //Search for link with REL set to ajax
    $('a[rel=ajax]').click(function () {
        //grab the full url
        var hash = this.href;
        //remove the # value
        hash = hash.replace(/^.*#/, '');
        //for back button
        $.history.load(hash);   
        //clear the selected class and add the class class to the selected link
        $('a[rel=ajax]').removeClass('selected');
        $(this).addClass('selected');
        //hide the content and show the progress bar
        //$('#content').hide();
        $('#loading').show();
        //run the ajax
        getPage();      
        //cancel the anchor tag behaviour
        return false;
    }); 
});

function pageload(hash) {
    //if hash value exists, run the ajax
    if (hash) getPage();    
}
function getPage() {
    //generate the parameter for the php script
    var data = 'page=' + encodeURIComponent(document.location.hash);
    $.ajax({
        url: "loader.php",  
        type: "GET",        
        data: data,     
        cache: false,
        success: function (html) {  
            //hide the progress bar
            $('#loading').hide();   
            //add the content retrieved from ajax and put it in the #content div
            $('#content').html(html);
            //display the body with fadeIn transition
            $('#content').fadeIn('fast');

            SyntaxHighlighter.highlight();

            }       
    });
}
    </script>
<?
/*php page loader*/
switch($_GET['page']) {
case '#code' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/code.php'); break;
case '#design' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/design.php'); break;
case '#illustration' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/illustration.php'); break;
case '#writing' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/writing.php'); break;
case '#links' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/links.php'); break;
case '#about' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/about.php'); break;
}
echo $page;
/*deep linking*/
if( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && ( $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ) )
{ 
} else {
header("Location: /mysite/#/index");
}
?>

这里的echo语句是原因。include在成功/失败时返回一个布尔值TRUE/FALSE。你将其分配给$page,然后返回$page:

switch($_GET['page']) {
  case '#code' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/code.php'); break;
  case '#design' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/design.php'); break;
  case '#illustration' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/illustration.php'); break;
  case '#writing' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/writing.php'); break;
  case '#links' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/links.php'); break;
  case '#about' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/about.php'); break;
}
// $page is 0 or 1 based on successfully including a file...
// Boolean TRUE will cast to 1 when printed
// FALSE won't print anything...
echo $page;