Hello Silverstripe Community,
Nice to meet you ; )
I try to do a simple ajax navigation menu with jquery ... and i'm so confused ><((°>
I try to be clear to explain me.
I have one main template to "themes/tutorial/templates/Pages.ss and others views are in the Layout folder. All correct
I would like retrieve theirs html contents in my $Layout placeholder with ajax ...
See my init function in Page.php
/*-----------------------------------------------------------*/
public function init() {
Requirements::themedCSS('layout');
Requirements::themedCSS('typography');
Requirements::themedCSS('form');
Requirements::javascript('http://code.jquery.com/jquery-1.4.2.min.js');
Requirements::customScript(<<<JS
jQuery.noConflict();
JS
);
Requirements::customScript(<<<JS
jQuery(document).ready(function(){
jQuery('#Menu1 a').click(function(){
page = jQuery(this).attr('href');
jQuery.ajax({
url: page,
cache: false,
success:function(html){
display(html);
},
error:function(XMLHttpRequest,textStatus,errorThrown){
display(textStatus);
}
})
return false;
});
});
function display(html){
jQuery('#ContentContainer').empty();
jQuery('#ContentContainer').append(html);
}
JS
);
parent::init();
}
/*-----------------------------------------------------------*/
And see the links in Pages.ss
<ul id="Menu1">
<% control Menu(1) %>
<li class="$LinkingMode"><a href="$Link" title="Aller à la page "{$Title}"" class="nav">$MenuTitle</a></li>
<% end_control %>
</ul>
<div id="ContentContainer">
$Layout
</div>
/*-----------------------------------------------------------*/
It works ... because it's easy
But, Ajax Request return all html content (header, menu, content and footer) in the div ContentContainer...
OK normal because my URL ajax request (page = jQuery(this).attr('href');) is e.g : http://localhost/website/news
I think it's a RewriteRule probleme or routing SS story
I would like to know ... How can i do to have the good behaviour?
I hope don't have fully false in my simple ajax reflexion : )
Please somebody can help me ...
thx Matt ; )