每个链接都会发出ajaxy请求,尽管它';s不声明为ajaxy类
我的页面中有很多链接,如果我第一次单击ajaxy类中的链接,它将发出请求 第二次,当我单击另一个非ajaxy类的链接时,它将发出相同的请求,并在firebug中导致一些错误,但在客户端浏览器中看不到 第三次,当我单击ajaxy类的链接时,它将重定向到另一个页面,而不是请求ajaxy将页面加载到我的内容中 这是我的密码 在我的第一个部门每个链接都会发出ajaxy请求,尽管它';s不声明为ajaxy类,ajax,jquery,Ajax,Jquery,我的页面中有很多链接,如果我第一次单击ajaxy类中的链接,它将发出请求 第二次,当我单击另一个非ajaxy类的链接时,它将发出相同的请求,并在firebug中导致一些错误,但在客户端浏览器中看不到 第三次,当我单击ajaxy类的链接时,它将重定向到另一个页面,而不是请求ajaxy将页面加载到我的内容中 这是我的密码 在我的第一个部门 <div class="block"> <ul id="navigation"> <li class="odd">&l
<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>
(函数($){
var$body=$(document.body),
$menu=$(“#导航”),
$content=$(“#content”),
$current=$(“#current”);
$.Ajaxy.configure({
'方法':'获取',
“控制器”:{
'通用':{
请求:函数(){
var Ajaxy=$.Ajaxy;
if(Ajaxy.options.debug)window.console.debug('$.Ajaxy.Controllers.\u generic.request',[this,arguments]);
$body.addClass('loading');
返回true;
},
答复:函数(){
var Ajaxy=$.Ajaxy;var data=this.State.Response.data;var State=this.State | |“未知”;
if(Ajaxy.options.debug)window.console.debug('$.Ajaxy.Controllers.\u generic.response',[this,arguments],data,state);
var title=data.title | | false;//如果我们在响应JSON中有一个标题
if(!title&&this.state | | false)title='jQuery Ajaxy-'+this.state;//如果不使用状态作为标题
if(title)document.title=title;//如果我们有一个新标题,请使用它
$body.removeClass('load');
$('#current').text('我们当前的状态是:['+state+']);
返回true;
},
错误:函数(){
var Ajaxy=$.Ajaxy;var data=this.State.Error.data | | this.State.Response.data;var State=this.State | | |“未知”;
var error=data.error | | data.responseText | | |“未知错误”;
var error|u message=data.content | | error;
window.console.error('$.Ajaxy.Controllers.\u generic.error',[this,arguments],error\u消息);
$body.removeClass('load');
$('#current').text('我们当前的状态是:['+state+']);
返回true;
}
},
“第页”:{
类名:“ajaxy页面”,
匹配:/^\/index.php\/?/,
请求:函数(){
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);
返回true;
},
答复:函数(){
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')。同胞('.active')。removeClass('active');
var Action=此;
$content.html(data.content).fadeIn(400,function(){
行动.文件准备($内容);
});
返回true;
}
}
}
});
})(jQuery);