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索引加载到带有 class 的 div 中content

为什么这两个样本不能一起工作?

4

1 回答 1

0

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

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

if (document.url != 'http://laynestaley.co.uk/test/#!/') {
    $('.content').load('http://mysite.com/test/'+fragment+'?ajax=1');
}
于 2011-06-17T21:34:18.813 回答