Jquery:加载一个 HTML 页面,然后通过 AJAX 加载另一个 html 页面
//when document loads
$(document).ready(function() {
//navigation item is clicked
$('.nav_item').click(function() {
//get the clicked nav items id
var nav_item = $(this).attr("id");
var location_to_load = nav_item + '.html';
//load the loading html then the page
$('#sliding_content_container').load('loading.html', null, showResponse);
//load the page
function showResponse(){
$('#sliding_content_container').delay(900).load(location_to_load);
};
//dont refresh
return false;
});
});
嘿,我正在学习 Jquery,只是想知道为什么我不能调用“加载页面”,然后延迟调用目的地,似乎我尝试的一切都不起作用,例如添加 .delay 或链接函数。
任何帮助都会很棒,我正在给 jquery 一个很好的老破解。
谢谢
//when document loads
$(document).ready(function() {
//navigation item is clicked
$('.nav_item').click(function() {
//get the clicked nav items id
var nav_item = $(this).attr("id");
var location_to_load = nav_item + '.html';
//load the loading html then the page
$('#sliding_content_container').load('loading.html', null, showResponse);
//load the page
function showResponse(){
$('#sliding_content_container').delay(900).load(location_to_load);
};
//dont refresh
return false;
});
});
Hey, I'm learning Jquery and just wondered why I can't call a "loading page" and then the destination with a delay, it seems everything I try doesn't work for instance adding .delay on or chaining the functions..
any help will be great, I'm giving jquery a good old crack.
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
delay
方法用于动画。它将一个延迟项目添加到动画队列中,延迟在其之后调用的任何动画。
不会影响正常方法。
相反,您应该调用
setTimeout
函数,例如这:The
delay
method is used for animations.It adds a delay item to the animation queue, delaying any animations called after it.
It will not affect normal methods.
Instead, you should call the
setTimeout
function, like this:为了使延迟发挥作用,您需要使用队列来加载
showResponse()
中的下一次调用。如果您愿意,您还可以使用“fx”以外的队列,以防您因为该队列通常用于动画而感到烦恼。
For delay to work, you need to use the queue for your next call to load in
showResponse()
.If you want to, you can also use a queue other than 'fx', in case it bugs you that this queue is usually used for animations.
这是正常的,你不能用 .delay(); 来延迟它。
AJAX 默认情况下是异步的(有时有助于检查技术缩写的含义)。
自从我使用 jQuery 以来已经有很长一段时间了,但据我记得 .ajax 请求应该是合适的。
http://api.jquery.com/jQuery.ajax/
It's normal, that you cannot delay it with .delay();
AJAX is asynchronous by default (sometimes it helps to check what abbreviation of technology means).
It's quite a lot of time since I used jQuery, but as far as i remember .ajax request should be suitable.
http://api.jquery.com/jQuery.ajax/