2011-12-20 27 views
4

我得到一個非常惱人的和神祕的「1」顯示在每個頁面的右下角從我假設是在以下ajax請求和PHP的某處的錯誤碼。標記爲php加載器的部分是該名稱的單獨頁面。 html只是li的哈希標記和rel =「ajax」出現在加載的內容結尾的神祕「1」

$(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"); 
} 
?> 
+2

+1如果只爲標籤「神祕」 – pilcrow 2011-12-20 03:23:36

回答

8

這裏的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; 
+0

我會檢查這個當我回到我的電腦,但將jQuery的仍然沒有工作回聲聲明? – expiredninja 2011-12-20 22:50:48

+0

除非包含的文件使用return關鍵字返回一個字符串,否則jquery將不受影響。但是,既然你得到了1似乎並非如此。應該沒事。 – 2011-12-21 00:11:24