Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php AJAX加载页面提供空的$\u GET_Php_Javascript_Jquery_Ajax - Fatal编程技术网

Php AJAX加载页面提供空的$\u GET

Php AJAX加载页面提供空的$\u GET,php,javascript,jquery,ajax,Php,Javascript,Jquery,Ajax,通过AJAX方法加载的页面。index.php是基本页面,profile.php是加载的页面 jQuery:(“post”与HTML请求无关) $\u在profile.php上获得打印: Array () 应要求;ajax加载javascript(index.php): 解决方案: 在根页面(index.php)上创建全局存储 在存储器中设置变量,而不是使用$\u GET 从子页面访问变量 例如: index.php(Javascript) 您在代码中的何处加载profile.php?它位于i

通过AJAX方法加载的页面。index.php是基本页面,profile.php是加载的页面

jQuery:(“post”与HTML请求无关)

$\u在profile.php上获得打印:

Array ()
应要求;ajax加载javascript(index.php):

解决方案:

  • 在根页面(index.php)上创建全局存储
  • 在存储器中设置变量,而不是使用$\u GET
  • 从子页面访问变量
  • 例如:

    index.php(Javascript)


    您在代码中的何处加载
    profile.php
    ?它位于index.php document.ready函数中。它相当长,但是页面加载工作正常(除了前面提到的问题)。我们需要查看发送ajax请求的部分。那么您的URL是否与
    loadPage
    中的类似?在我看来,您正在删除
    #
    并添加
    .php
    ,这将提供
    profile.php
    。其中没有查询字符串,通常$\u GET`为空。这仅适用于.load()函数,该函数需要指向一个文件才能提取其内容。我有一个名为“profile.php”的页面。链接所做的是在片段之前添加
    ?userID=1
    ,本质上是发出服务器请求
    index.php?userID=1
    。我是AJAX新手,所以我不确定链接文件(profile.php)是否可以访问基本文件(index.php)的GET请求……但这怎么可能呢?
    <a href="?userID=1#profile">Firstname Lastname</a>
    
    http://########/#####/index.php?userID=1#home
    
    Array ()
    
        //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);
            }
    
    if (typeof(window.storage) === 'undefined') {
        window.storagePV = {};
    }
    
    $('#nav-profile').click(function() {
        window.storage.userID = <?php echo "$_SESSION[userID]"; ?>;
    });
    
    var userID = window.storage.userID