PHP 和 JavaScript 代码帮助
可能的重复:
页面加载内容、内部内容时出现问题
所以我遇到了问题,我将重印的两段代码工作得很好,直到引入了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的根页面正在将自身加载到 div 中。
以一种快速而肮脏的方式,你可以检查以确保
Your root page is loading itself into the div.
In a quick and dirty way, you could just check to make sure