Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.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 jquery地址爬网-逻辑问题_Php_Jquery_Ajax_Jquery Address - Fatal编程技术网

Php jquery地址爬网-逻辑问题

Php jquery地址爬网-逻辑问题,php,jquery,ajax,jquery-address,Php,Jquery,Ajax,Jquery Address,我正在使用jquery地址插件构建一个ajax驱动的站点,我已经让它工作了!耶!就本问题而言,我们可以使用测试场地: 我必须删除对urlencode的两个调用才能使爬行示例正常工作 我遇到了$crawling->nav调用的问题。它基本上使用js和php将xml文件的一部分加载到dom中。我基本上了解它是如何工作的,我想修改示例代码以包含子页面 例如,我想在“/”上显示“subnav project.html”/项目'和'//项目/蓝色',但不在'//联络人'。要做到这一点,我认为php应该“

我正在使用jquery地址插件构建一个ajax驱动的站点,我已经让它工作了!耶!就本问题而言,我们可以使用测试场地:

我必须删除对urlencode的两个调用才能使爬行示例正常工作

我遇到了$crawling->nav调用的问题。它基本上使用js和php将xml文件的一部分加载到dom中。我基本上了解它是如何工作的,我想修改示例代码以包含子页面

例如,我想在“/”上显示“subnav project.html”/项目'和'//项目/蓝色',但不在'//联络人'。要做到这一点,我认为php应该“知道”用户在哪一页上,这样我就可以根据这一点建立我的逻辑

这疯了吗?如果我以这种方式构建网站,php能知道网站的当前状态吗?如果没有,如何有选择地加载html片段,或修改导航菜单中显示的链接

我以前从来没有对ajax太疯狂过,所以任何反馈都会很有帮助

编辑 这是爬行类

class Crawling { 

    const fragment = '_escaped_fragment_';

    function Crawling(){ 

        // Initializes the fragment value
        $fragment = (!isset($_REQUEST[self::fragment]) || $_REQUEST[self::fragment] == '') ? '/' : $_REQUEST[self::fragment];

        // Parses parameters if any
        $this->parameters = array();
        $arr = explode('?', $fragment);
        if (count($arr) > 1) {
            parse_str($arr[1], $this->parameters);
        }

        // Adds support for both /name and /?page=name
        if (isset($this->parameters['page'])) {
            $this->page = '/?page=' . $this->parameters['page'];
        } else {
            $this->page = $arr[0];
        }

        // Loads the data file
        $this->doc = new DOMDocument();
        $this->doc->load('data.xml');
        $this->xp = new DOMXPath($this->doc);
        $this->nodes = $this->xp->query('/data/page');
        $this->node = $this->xp->query('/data/page[@href="' . $this->page . '"]')->item(0);

        if (!isset($this->node)) {
            header("HTTP/1.0 404 Not Found");
        }
    }

    function base() {
        $arr = explode('?', $_SERVER['REQUEST_URI']);
        return $arr[0] != '/' ? preg_replace('/\/$/', '', $arr[0]) : $arr[0];
    }

    function title() {
        if (isset($this->node)) {
            $title = $this->node->getAttribute('title');
        } else {
            $title = 'Page not found';
        }
        echo($title);
    }

    function nav() {
        $str = '';

        // Prepares the navigation links
        foreach ($this->nodes as $node) {
            $href = $node->getAttribute('href');
            $title = $node->getAttribute('title');
            $str .= '<li><a href="' . $this->base() . ($href == '/' ? '' : '?' . self::fragment . '=' .html_entity_decode($href)) . '"' 
                . ($this->page == $href ? ' class="selected"' : '') . '>' 
                . $title . '</a></li>';
        }
        echo($str);
    }

    function content() {
        $str = '';

        // Prepares the content with support for a simple "More..." link
        if (isset($this->node)) {
            foreach ($this->node->childNodes as $node) {
                if (!isset($this->parameters['more']) && $node->nodeType == XML_COMMENT_NODE && $node->nodeValue == ' page break ') {
                    $str .= '<p><a href="' . $this->page . 
                        (count($this->parameters) == 0 ? '?' : '&') . 'more=true' . '">More...</a></p>';
                    break;
                } else {
                    $str .= $this->doc->saveXML($node);
                }
            }
        } else {
            $str .= '<p>Page not found.</p>';
        }

        echo(preg_replace_callback('/href="(\/[^"]+|\/)"/', array(get_class($this), 'callback'), $str));
    }

    private function callback($m) {
        return 'href="' . ($m[1] == '/' ? $this->base() : ($this->base() . '?' . self::fragment . '=' .$m[1])) . '"';
    }
}

$crawling = new Crawling();

您将无法使用片段标识符(即字符右侧的所有内容)做出服务器端决策。这是因为浏览器不向服务器发送片段标识符。如果您想要做出服务器端决策,则需要使用一些JavaScript帮助,包括AJAX来传达当前片段标识符是什么。

riiIIlight。这是行动指令吗?1.我浏览到这个页面。2.php执行。3.我正试图使用js来修改php正在做的事情,但为时已晚!是否有一个术语用于使用JS辅助将当前片段标识符传回服务器端脚本?我想查一本好的教程。谢谢我不知道你说的操作顺序是什么意思。尽管我只是仔细查看了示例页面,并注意到您已经通过AJAX将片段标识符发送到服务器,并且显然已经使用该片段标识符来提供正确的内容。因此,鉴于上述情况,我现在对你的处境感到困惑,因为这似乎是大部分工作。如果我们看到您的服务器端代码,可能会更有意义。基本上,我正在尝试测试“/”是否正确/已加载“somepage”。如果为真:显示导航,否则不显示。我试图在“导航”功能中完成这项工作。