如何用jQuery阿贾克斯刷新页面? [英] How to refresh page with jQuery Ajax?

查看:237
本文介绍了如何用jQuery阿贾克斯刷新页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要的刷新整个页面使用Ajax,点击一些初步的站点链接后。

I want to refresh a full page with ajax, after clicking on some initial site link.

示例:

我们已经打开网站www.love.com,它有一个链接,www.love.com/somepage.html~~V

We have opened site www.love.com, it has a link to www.love.com/somepage.html

在我们点击这个链接,整版必须用AJAX(由somepage.html代替活动页面)刷新

After we click on this link, full page must be refreshed with ajax (replaced active page by somepage.html)

和存在必须有一些淡入/淡出效果,当页面被替换。

And there is must be some fadeIn/Out effect, when the page is replaced.

如何?

也许有些插件可以做到这一点,任何一个环节?

maybe some plugin can do this, any link?

推荐答案

好样的一个整版的要求相矛盾AJAX的目的,

Well a full-page request kind of contradict the purpose of AJAX,

但如果你坚持:) 你可以使用一个巨大的股利为你的页面的占位符,使用jQuery负载/阿贾克斯

but if you insist :) you can use a huge div as a placeholder of your page, and use jQuery Load/Ajax

在div是这样

<div id="yourhugediv"></div>

和您可以使用功能

function changeUrl(href)
{
   $('#yourhugediv').load(href);
   href = (href == "") ? "/" : href;
   uri = window.location.href.split("#/");
   window.location.href = uri[0] + "#/" + href;
}

手动添加的功能,你的链接

either manually add the function to your link

<a href="#" onclick="changeUrl('http://love.com/somepage.html')">to load</>

或使用jQuery选择遍历每个锚

or use jQuery selector to iterate every anchor

$('a').click(function()
{
    changeUrl(a.attr('href'));
});
$('a').attr('href','#');

这篇关于如何用jQuery阿贾克斯刷新页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆