PHP 和 JavaScript 代码帮助

发布于 2024-11-15 21:36:27 字数 1811 浏览 4 评论 0原文

可能的重复:
页面加载内容、内部内容时出现问题

所以我遇到了问题,我将重印的两段代码工作得很好,直到引入了 jQuery 插件。首先是 JavaScript:

$(document).ready(function() {
            $.address.crawlable(true).init(function(event) {
                $('.nav a').address();
            }).change(function(event) {
                $('.nav a').each(function() {
                    $(this).toggleClass('selected', $(this).attr('href') == '#!' + event.value);
                });
               fragment = event.value.slice(1).replace('!', '');
        $('.content').load('http://mysite.com/test/'+fragment+'?ajax=1');


            });
    });

现在是 PHP:

<?php

$base = 'http://mysite.com/test';

include('data.php');

if ($fragment = $_GET['_escaped_fragment_']) {
    // OPTION 1: if Google is reqesting an '_escaped_fragment_=' page, then redirect to a clean URL
    header("Location: $base/$fragment", 1, 301);
    exit;
}

if ($_GET['url']){
    // If there's a URL parameter, then load the data.
    $data = loaddata($_GET['url']);
    if ($_GET['ajax'] == 1){
        // OPTION 2: If the user's browser is requesting just the data (as an AJAX request), that's all we'll return
        echo $data;
        exit;
    }
} else {
    $data = '<p>Select a link from above to get started :)</p>';
}

//OPTION 3: a user or bot is requesting an HTML page, and we're return that to them now.


?>

发生的事情在这里可见:http://laynestaley.co.uk/ test/

页面加载被触发,然后不断地反复触发,将 test 索引加载到类 content 的 div 中。

为什么这两个示例不能一起工作?

Possible Duplicate:
Problem with page loading content, inside content

so im having problems, the two pieces of code i will reprint worked fine until is introduced a jQuery plugin. Firstly the JavaScript:

$(document).ready(function() {
            $.address.crawlable(true).init(function(event) {
                $('.nav a').address();
            }).change(function(event) {
                $('.nav a').each(function() {
                    $(this).toggleClass('selected', $(this).attr('href') == '#!' + event.value);
                });
               fragment = event.value.slice(1).replace('!', '');
        $('.content').load('http://mysite.com/test/'+fragment+'?ajax=1');


            });
    });

And now the PHP:

<?php

$base = 'http://mysite.com/test';

include('data.php');

if ($fragment = $_GET['_escaped_fragment_']) {
    // OPTION 1: if Google is reqesting an '_escaped_fragment_=' page, then redirect to a clean URL
    header("Location: $base/$fragment", 1, 301);
    exit;
}

if ($_GET['url']){
    // If there's a URL parameter, then load the data.
    $data = loaddata($_GET['url']);
    if ($_GET['ajax'] == 1){
        // OPTION 2: If the user's browser is requesting just the data (as an AJAX request), that's all we'll return
        echo $data;
        exit;
    }
} else {
    $data = '<p>Select a link from above to get started :)</p>';
}

//OPTION 3: a user or bot is requesting an HTML page, and we're return that to them now.


?>

Whats happening is visible here: http://laynestaley.co.uk/test/

The page load is fired and then constantly fired over and over, loading the test index into a div with class content.

Why do these two samples not work together?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

婴鹅 2024-11-22 21:36:27

您的根页面正在将自身加载到 div 中。

以一种快速而肮脏的方式,你可以检查以确保

if (document.url != 'http://laynestaley.co.uk/test/#!/') {
    $('.content').load('http://mysite.com/test/'+fragment+'?ajax=1');
}

Your root page is loading itself into the div.

In a quick and dirty way, you could just check to make sure

if (document.url != 'http://laynestaley.co.uk/test/#!/') {
    $('.content').load('http://mysite.com/test/'+fragment+'?ajax=1');
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文