我使用的是Ajaxy jQuery插件:http://balupton.com/sandbox/jquery-ajaxy/
当我访问http://www.example.com/#/foo/时,foo的内容没有显示出来。而是显示我的index.php在root中的内容。
这就是我初学ajaxy的方式:
var $body = $(document.body),
$menu = $('#wrapper'),
$content = $('#wrapper')
$.Ajaxy.configure({
'Controllers': {
'_generic': {
request: function(){
// Loading
$body.addClass('loading');
// Done
return true;
},
response: function(){
// Prepare
var Ajaxy = $.Ajaxy; var data = this.State.Response.data; var state = this.state||'unknown';
// Title
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
// Loaded
$body.removeClass('loading');
// Return true
return true;
},
error: function(){
// Prepare
var Ajaxy = $.Ajaxy; var data = this.State.Error.data||this.State.Response.data; var state = this.state||'unknown';
// Error
var error = data.error||data.responseText||'Unknown Error.';
var error_message = data.content||error;
// Log what is happening
window.console.error('$.Ajaxy.Controllers._generic.error', [this, arguments], error_message);
// Loaded
$body.removeClass('loading');
// Done
return true;
}
},
'page': {
classname: 'ajaxy-page',
matches: /^\/pages\/?/,
data: {ajaxy : true},
request: function(){
// Prepare
var Ajaxy = $.Ajaxy;
console.log(this);
// Adjust Menu
$menu.find('.active').removeClass('active');
// Hide Content
$content.stop(true,true).fadeOut(400);
console.log(arguments)
// Return true
return true;
},
response: function(){
// Prepare
var Ajaxy = $.Ajaxy; var data = this.State.Response.data; var state = this.state; var State = this.State;
// Adjust Menu
$menu.children(':has(a[href*="'+State.raw.state+'"])').addClass('active').siblings('.active').removeClass('active');
// Show Content
var Action = this;
console.log(data);
$content.html(data.content).fadeIn(400,function(){
Action.documentReady($content);
});
// Return true
return true;
}
}
},
root_url: url + '/',
relative_url: url + '/',
redirect: true
});
提前致谢
的Lukas
答案 0 :(得分:0)
我找到了解决方案。问题是控制器的“匹配”选项:
matches: /^\/pages\/?/
我改为:
matches: /\//
非常感谢
的Lukas