我一直绞尽脑汁,几乎整整一天都在搜索谷歌,为什么这样做不起作用.作为改进我自己网站的实验,我在这里查看教程http://tutorialzine.com/2009/09/simple-ajax-website-jquery/最重要的是ajax/jquery部分.
基本上,该教程的POST与页码一起使用,但我一直在尝试将其转换为使用页面名称.因此,从href开始需要#!home(hashbangs用于实现谷歌兼容性),php可以将其解析为"home.html"并将其加载到内容div中.由于我以外的原因,它不会起作用.我将发布我试图修改的相关代码段,对我有利:
从javascript加载器(只有我修改的结束部分):
var datastring=url.replace('#!',''); //strip the #page part of the hash and leave only the page number
$('#loading').css('visibility','visible'); //show the rotating gif animation
$.ajax({ //create an ajax request to load_page.php
type: "POST",
url: "load_file.php",
data: datastring, //with the page number as a parameter
dataType: "html", //expect html to be returned
async: false,
success: function(msg){
if(parseInt(msg)!=0) //if no errors
{
$('#content').html(msg); //load the returned html into pageContet
$('#loading').css('visibility','hidden'); //and hide the rotating gif
}
}
});
Run Code Online (Sandbox Code Playgroud)
和整个php文件:
<?php …Run Code Online (Sandbox Code Playgroud)