php – 神秘的“1”出现在加载内容的末尾
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php – 神秘的“1”出现在加载内容的末尾,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3084字,纯文字阅读大概需要5分钟。
内容图文
![php – 神秘的“1”出现在加载内容的末尾](/upload/InfoBanner/zyjiaocheng/808/bb42067481c241bba60537025bb8e2a1.jpg)
我在每个页面的右下方显示一个非常恼人和神秘的“1”,我假设在下面的ajax请求和php代码中出现了错误.标记为php加载程序的部分是该名称的单独页面. html只是带有哈希标签的li和rel =“ajax”
$(document).ready(function () {
//Check if url hash value exists (for bookmark)
$.history.init(pageload);
//highlight the selected link
$('a[href=' + document.location.hash + ']').addClass('selected');
//Search for link with REL set to ajax
$('a[rel=ajax]').click(function () {
//grab the full url
var hash = this.href;
//remove the # value
hash = hash.replace(/^.*#/, '');
//for back button
$.history.load(hash);
//clear the selected class and add the class class to the selected link
$('a[rel=ajax]').removeClass('selected');
$(this).addClass('selected');
//hide the content and show the progress bar
//$('#content').hide();
$('#loading').show();
//run the ajax
getPage();
//cancel the anchor tag behaviour
return false;
});
});
function pageload(hash) {
//if hash value exists, run the ajax
if (hash) getPage();
}
function getPage() {
//generate the parameter for the php script
var data = 'page=' + encodeURIComponent(document.location.hash);
$.ajax({
url: "loader.php",
type: "GET",
data: data,
cache: false,
success: function (html) {
//hide the progress bar
$('#loading').hide();
//add the content retrieved from ajax and put it in the #content div
$('#content').html(html);
//display the body with fadeIn transition
$('#content').fadeIn('fast');
SyntaxHighlighter.highlight();
}
});
}
</script>
<?
/*php page loader*/
switch($_GET['page']) {
case '#code' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/code.php'); break;
case '#design' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/design.php'); break;
case '#illustration' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/illustration.php'); break;
case '#writing' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/writing.php'); break;
case '#links' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/links.php'); break;
case '#about' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/about.php'); break;
}
echo $page;
/*deep linking*/
if( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && ( $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ) )
{
} else {
header("Location: /mysite/#/index");
}
?>
解决方法:
这里的echo语句是原因. include在成功/失败时返回布尔值TRUE / FALSE.你将它分配给$page然后回显$page:
switch($_GET['page']) {
case '#code' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/code.php'); break;
case '#design' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/design.php'); break;
case '#illustration' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/illustration.php'); break;
case '#writing' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/writing.php'); break;
case '#links' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/links.php'); break;
case '#about' : $page = include ($_SERVER['DOCUMENT_ROOT'].'/mysite/about.php'); break;
}
// $page is 0 or 1 based on successfully including a file...
// Boolean TRUE will cast to 1 when printed
// FALSE won't print anything...
echo $page;
内容总结
以上是互联网集市为您收集整理的php – 神秘的“1”出现在加载内容的末尾全部内容,希望文章能够帮你解决php – 神秘的“1”出现在加载内容的末尾所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。