I am unsure if I am going about dynamically updating the content on this site properly. As I get deeper into building the site I have began to realize that my functions are going to be crazy..
The code is working however I am adding a new function for each menu item. I was looking for a way to simplify that. Would it be possible to somehow use one function to handle the changing of the content for each of the onclick events I've setup? Maybe its time to pick up a book, any suggestions are welcomed.
HTML:
<ul id="mainNav">
<li><a href="#" onclick="contentAjax()">HOME</a></li>
<li><a href="#" onclick="contentAjaxDocs()">DOCS</a></li>
<li><a href="#" onclick="contentAjaxServers()">SERVERS</a></li>
<li><a href="#" onclick="contentAjaxMonitors()">MONITORS</a></li>
</ul>
Javascript:
function contentAjax() {
var request = $.ajax({
url: '/resources/templates/home.php',
type: "GET",
dataType: "html"
});
request.done(function(msg) {
$("#content").html(msg);
});
request.fail(function(jqXHR, textStatus) {
alert( "Request failed: " + textStatus );
});
var request2 =
$.ajax({
url: '/resources/templates/homerightPanel.php',
type: "GET",
dataType: "html"
});
request2.done(function(msg) {
$("#rightPanel").html(msg);
});
request2.fail(function(jqXHR, textStatus) {
alert( "Request failed: " + textStatus );
});
}