I'm learning CakePHP and I need to make an AJAX menu (a menu which doesn't reload the page once you click on the links).
I could easily do that with JavaScript with something like:
function loadPage(page) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
document.getElementById("container").innerHTML = xhttp.responseText;
}
};
xhttp.open("GET", page, true);
xhttp.send();
}
and then call it for each button on the menu and its corresponding page, with only the HTML code that would go in the "container" id'd div:
window.onload = function() {
document.getElementById("homeButton").onclick = function() { loadPage("home.html"); }
document.getElementById("newsButton").onclick = function() { loadPage("news.html"); }
document.getElementById("aboutButton").onclick = function() { loadPage("about.html"); }
document.getElementById("registerButton").onclick = function() { loadPage("contact.html"); }
}
Well now, since I'm not very familiarized with the CakePHP framework and how it works the HTTP requests i'm having some trouble.
How would you do that in CakePHP?
I appreciate the help, good day.