0

AJAXメソッドを介してロードされたページ。index.phpはベースページ、profile.phpはロードされたページです

jQuery :(「投稿」はHTMLリクエストとは何の関係もありません)

$('<a/>', {href: '?userID='+post['userID']+'#profile'}).text(post['firstName']+' '+post['lastName'])

HTML:

<a href="?userID=1#profile">Firstname Lastname</a>

生のURL(クリック後)

http://########/#####/index.php?userID=1#home

profile.phpの$_GETprint_r:

Array ()

リクエストにより; ajaxロードjavascript(index.php):

    //AJAX page loading

        $(document).ready(function(){

            //Default page
            if(!window.location.hash)
                window.location.hash = '#home';

            //Check page reference
            checkURL();

            //Update nav
            $('#main-nav li').on("click", function (){
                $('#main-nav li').removeClass('active');
                $(this).addClass('active');

                //Assign each link a new onclick event, using their own hash as a parameter
                checkURL(this.hash);    
            });

            //check for a change in the URL every 250 ms to detect if the history buttons have been used
            setInterval("checkURL()",250);  
        });

        //Store the current URL hash
        var lasturl=""; 

        function checkURL(hash){
            if(!hash)

                //if no parameter is provided, use the hash value from the current address
                hash=window.location.hash;
            if(hash != lasturl) { 

                //If hash changed, update current hash and load new one
                lasturl=hash;
                loadPage(hash);
            }

        }

        function loadPage(url) {

            //Adjust page name
            url=url.replace('#','');   
            url=url+'.php';

            //AJAX load page contents in to main content div
            $('#content').load(url);
        }
4

1 に答える 1

0

解決:

  1. ルートページ(index.php)にグローバルストレージを作成します。
  2. $ _GETを使用する代わりに、ストレージに変数を設定します。
  3. 子ページから変数にアクセスします。

例:

index.php(Javascript)

if (typeof(window.storage) === 'undefined') {
    window.storagePV = {};
}

$('#nav-profile').click(function() {
    window.storage.userID = <?php echo "$_SESSION[userID]"; ?>;
});

userIDにアクセスしてユーザーのプロファイルページを表示する

var userID = window.storage.userID
于 2013-03-15T01:52:37.617 に答える