我的页面中有很多链接,如果我第一次点击ajaxy类的链接,它会发出请求
第二次当我点击另一个不是ajaxy类的链接时,它会发出相同的请求并在firebug中导致一些错误,但是在客户端浏览器中看不到它。
第三次当我点击ajaxy类的链接时,它会重定向到另一个页面,而不是发出ajaxy请求将页面加载到我的内容中..
这是我的代码
在我的第一个div
<div class="block">
<ul id="navigation">
<li class="odd"><a href="./index.php/aaa/bbb/ccc/first" class="ajaxy ajaxy-page">First</a></li>
</ul>
</div>
我的第二个div
<div class="block">
<ul id="navigation1">
<li class="odd"><a href="./index.php/aaa/bbb/ccc/second" class="other">Second</a></li>
</ul>
</div>
我的主要内容是显示请求的结果
<div id="maincol">
<div id="result">
<div id="content"></div>
<div id="current" style="visibility:hidden"></div>
</div>
以及创建ajaxy请求的代码
<script type="text/javascript">
(function($){
var $body = $(document.body),
$menu = $('#navigation'),
$content = $('#content'),
$current = $('#current');
$.Ajaxy.configure({
'method': 'get',
'Controllers': {
'_generic': {
request: function(){
var Ajaxy = $.Ajaxy;
if ( Ajaxy.options.debug ) window.console.debug('$.Ajaxy.Controllers._generic.request', [this,arguments]);
$body.addClass('loading');
return true;
},
response: function(){
var Ajaxy = $.Ajaxy; var data = this.State.Response.data; var state = this.state||'unknown';
if ( Ajaxy.options.debug ) window.console.debug('$.Ajaxy.Controllers._generic.response', [this,arguments], data, state);
var title = data.title||false; // if we have a title in the response JSON
if ( !title && this.state||false ) title = 'jQuery Ajaxy - '+this.state; // if not use the state as the title
if ( title ) document.title = title; // if we have a new title use it
$body.removeClass('loading');
$('#current').text('Our current state is: ['+state+']');
return true;
},
error: function(){
var Ajaxy = $.Ajaxy; var data = this.State.Error.data||this.State.Response.data; var state = this.state||'unknown';
var error = data.error||data.responseText||'Unknown Error.';
var error_message = data.content||error;
window.console.error('$.Ajaxy.Controllers._generic.error', [this, arguments], error_message);
$body.removeClass('loading');
$('#current').text('Our current state is: ['+state+']');
return true;
}
},
'page': {
classname: 'ajaxy-page',
matches: /^\/index.php\/?/,
request: function(){
var Ajaxy = $.Ajaxy;
if ( Ajaxy.options.debug ) window.console.debug('$.Ajaxy.Controllers.page.request', [this,arguments]);
$menu.find('.active').removeClass('active');
$content.stop(true,true).fadeOut(400);
return true;
},
response: function(){
var Ajaxy = $.Ajaxy; var data = this.State.Response.data; var state = this.state; var State = this.State;
if ( Ajaxy.options.debug ) window.console.debug('$.Ajaxy.Controllers.page.response', [this,arguments], data, state);
$menu.children(':has(a[href*="'+State.raw.state+'"])').addClass('active').siblings('.active').removeClass('active');
var Action = this;
$content.html(data.content).fadeIn(400,function(){
Action.documentReady($content);
});
return true;
}
}
}
});
})(jQuery);
</script>