2011-12-20 12 views
4

次のajaxリクエストとphpのどこかで間違いがあると仮定して、各ページの右下に非常に厄介で不思議な "1"コード。 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

答えて

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

+0

jqueryは、インクルードされたファイルがreturnキーワードで文字列を返さない限り影響を受けません。しかし、あなたが1であるように見えるので、そうではないようです。うまくいくはずです。 –

関連する問題