我正在一个邮件系统。 我已经完成了收件箱和消息观看部分。 他们被加载在用户帐户页面上的DIV,这一切与作品进行刷新页面。
我根据这个jQuery开发上的这篇文章 。
得到了一些帮助,在这里得到的消息链接到与出刷新页面,以及如何添加一个过滤器,让资料链接竟然刷新到实际的个人资料页的专区内打开邮件。 这一切都很好。
我转移到使用模态(Twitter的引导)来加载外部形式的消息发送方。 这工作过,但现在我已经花了年龄试图找出如何做我的链接做同样的事情,与表单提交即得到它与出刷新整个页面提交。 同样,我使用几乎相同的jQuery作为收件箱中的一部分。
下面是收件箱中的代码:
<p id="waiting"><!-- ajax loading --></p>
<div class="messages"><!-- inbox --></div>
使用Javascript:
$.ajaxSetup({ cache: false});
$(document).ready(function(){
// set up the click event
$('a.loader').live('click', function() {
var toLoad = '<? echo base_url(); ?>user/messaging/';
$('.messages').fadeOut(100, loadContent);
$('#load').remove();
$('#waiting').append('<div id="load" style="height: 700px; background:url(<? echo base_url(); ?>files/recordCovers/index.html?<? echo rand(5,1555); ?>); background-size: cover;"><div class="circle"></div><div class="circle1"></div></div>');
$('#load').fadeOut(1000);
function loadContent() {
$('.messages').load(toLoad, '', function(response, status, xhr) {
if (status == 'error') {
var msg = "Sorry but there was an error: ";
$(".messages").html(msg + xhr.status + " " + xhr.statusText);
}
}).fadeIn(4000, hideLoader());
}
function hideLoader() {
$('#load').fadeOut(2000);
}
return false;
});
});
<? // this makes the links open in the same div
// a:not(.profile) allows profile links to open in browser window
// we put class="profile" on profile links.?>
$(".messages").on("click", "a:not(.profile)", function (e) {
$(".messages").load($(this).attr("href"));
e.preventDefault();
});