2

リンクをクリックした後に外部phpファイルを表示し、別のリンクをクリックした後にそのすぐ下に別の外部ファイル(の代わりではない)を表示する方法があるかどうか知りたいです。これが私のコードです。

index.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html>  
<head>
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-   1.2.6.pack.js"></script>  
<script type="text/javascript" src="core.js"></script>   
</head>  
<body>   
<div id="menu">  
<ul>  
<li id="home"><a href="#downloads">DOWNLOADS</a></li>  
<li id="tutorials"><a href="#errors">ERRORS</a></li>  
</ul>   
</div>  
<div id="content">    
</div>  
</body>  
</html>  

core.js

//On load page, init the timer which check if the there are anchor changes each 300 ms
$().ready(function(){
setInterval("checkAnchor()", 100);
});
var currentAnchor = null;
//Function which chek if there are anchor changes, if there are, sends the ajax    petition
function checkAnchor(){
//Check if it has changes
if(currentAnchor != document.location.hash){
    currentAnchor = document.location.hash;
    //if there is not anchor, the loads the default section
    if(!currentAnchor)
        query = "page=1";
    else
    {
        //Creates the  string callback. This converts the url URL/#main&id=2 in URL/?section=main&id=2
        var splits = currentAnchor.substring(1).split('&');
        //Get the section
        var page = splits[0];
        delete splits[0];
        //Create the params string
        var params = splits.join('&');
        var query = "page=" + page + params;
    }
    //Send the petition
    $("#loading").show();
    $.get("callbacks.php",query, function(data){
        $("#content").html(data);
        $("#loading").hide();
    });
}
}

downloads.php

<b>DOWNLOADS</b>

errors.php

<b>ERRORS</b>

callbacks.php

<?php  
//used to simulate more waiting for load the content, remove on yor projects!  
sleep(1);  
//Captures the petition and load the suitable section  
switch($_GET['page']){  
case "errors": include 'errors.php'; break;
case "downloads": include 'downloads.php'; break;

default: include 'downloads.php'; break;

}  
?>

これは、スイッチを使用し、errors.phpとdownloads.phpの両方を同時に表示できるようにしたいことを除いて、完全に機能します。どちらか一方だけではありません。

編集

明確にするための擬似コード:

ダウンロードをクリックした場合は、download.phpのみを表示します。エラーがクリックされた場合は、error.phpのみを表示し(downloads.phpの直後)、downloads.phpまたはメインページにすでに含まれている場合と含まれていない場合があるその他の外部ファイルを削除しないでください。

助言がありますか?

ps私はこれについて多くのスレッドを調べましたが、それが私が試したすべてのコードを投稿できない理由です(申し訳ありませんが、リンクを含めることもできません。前回、私の質問がそれを行うことに反対しました...> :/)宿題を済ませたことを約束できます。

pssこれが反対票に値すると思われる場合は、その理由を説明してください。私は批判を受け入れますが、親指を下に向けるだけではまったく役に立ちません。

編集:

core.jsをに更新しました

$(document).ready(function(){
$('#menu li a').click(function() {
    var currentAnchor = $(this).attr('href');
    if(!currentAnchor)
        var query = "page=1";
    else
    {
        var splits = currentAnchor.substring(1).split('&');
        //Get the section
        var page = splits[0];
        delete splits[0];
        //Create the params string
        var params = splits.join('&');
        var query = "page=" + page + params;
    }
    //Send the petition
    $("#loading").show();
    $.get("callbacks.php",query, function(data){
        $("#content").html(data);
        $("#loading").hide();
    });       
    return false;
});
});
4

2 に答える 2

0

編集:

[ここで削除された紛らわしい部分]

-

編集:

core.js(改訂)

//On load page, init the timer which check if the there are anchor changes each 300 ms
$(document).ready(function(){
    $('#menu li a').click(function() {
        var currentAnchor = $(this).attr('href');
        if(!currentAnchor)
            var query = "page=1";
        else
        {
            var splits = currentAnchor.substring(1).split('&');
            //Get the section
            var page = splits[0];
            delete splits[0];
            //Create the params string
            var params = splits.join('&');
            var query = "page=" + page + params;
        }
        //Send the petition
        $("#loading").show();
        $.get("callbacks.php",query, function(data){
            $("#content").html(data);
            $("#loading").hide();
        });       
        return false;
    });
}​​​);​​​

-

編集:

これは、既存のコンテンツに[ダウンロードまたはエラーのいずれかからの]データを「追加」します。

        $.get("callbacks.php",query, function(data){
            $("#content").append(data);
            $("#loading").hide();
        }); 

お役に立てれば。

于 2012-06-20T18:37:55.217 に答える
0

両方のページを一度に表示したい場合は、callbacks.php ページで次のようにする必要があります (switch ステートメントを削除しただけです)。

include 'errors.php';
include 'downloads.php';

これができない理由はありますか?

于 2012-06-20T18:19:35.367 に答える