我正在使用它在加载 3 个页面之前显示加载图像。代码正在运行并显示加载图像,然后再从其他任何地方转到这些页面,然后是这 3 个页面。问题是当我去这些页面并在那里形成时,我点击了 3 个页面的链接之一,它什么也没做。只需在 url 的末尾添加一个 # 即可。
$.ajaxSetup({
cache: false
});
//Loading Image.
var ajax_load = "<img src='http://d2o0t5hpnwv4c1.cloudfront.net/412_ajaxCalls/DEMO/img/load.gif' alt='loading...' style='top:48%; left:48%; position:relative;'/>";
//PHP file URL.
var loadUrl = "/cakephp/Posts/index";
var loadUrl2 = "/cakephp/Posts/fetchHome";
var loadUrl3 = "/cakephp/accounts/getFollowers";
//$.get()
$("#dash").click(function(){
$(".container-fluid2").html(ajax_load);
$.get(
loadUrl,
{language: "php", version: 5},
function(responseText){
$(".container-fluid2").html(responseText);
history.replaceState(null, "Dashboard", "posts");
},
"html"
);
});
$("#home").click(function(){
$(".container-fluid2").html(ajax_load);
$.get(
loadUrl2,
{language: "php", version: 5},
function(responseText){
$(".container-fluid2").html(responseText);
history.replaceState(null, "Timeline", "posts/fetchHome");
},
"html"
);
});
$("#followers").click(function(){
$(".container-fluid2").html(ajax_load);
$.get(
loadUrl3,
{language: "php", version: 5},
function(responseText){
$(".container-fluid2").html(responseText);
history.replaceState(null, "View followers", "accounts/getFollowers");
},
"html"
);
});