Click here to Skip to main content
15,885,953 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello, I'm not exaclty sure how I can word this, but I'll give it a shot, and hopefully you guys understand what it is that I'm looking for.

Right now, I'm running a panel (CMS) and managing all of my content. I have it so I don't have to manually update each page for the navigation. The code I have is:

C#
$(function(){
  // Link handling.
  $('a[rel != "noAJAX"]').live('click', function(event){
    if ($(this).attr('name') != ""){
        var currentDiv = $(this).attr('name');
    }else{
        var currentDiv = divID;
    }
    $(currentDiv).html(loadingHTML);
    $(currentDiv).load($(this).attr('href'));
    event.preventDefault();
  });
  $('form[rel != "noAJAX"]').live('submit', function(event){
    if ($(this).attr('name') != ""){
        var currentDiv = $(this).attr('name');
    }else{
        var currentDiv = divID;
    }
    $(currentDiv).html(loadingHTML);
    $.post($(this).attr('action'), $(this).serialize(), function(html){
        $(currentDiv).html(html);
    });
    return false;
  });
});


XML
$(function(){
                divID = '#load';
                  loadingHTML = '<center><img style="margin-top:50px; margin-bottom: 50px;" src=""></center>';
                $('#load').load('front');
            });



Basically handles the div, and how pages interact with form submissions etc inside that page. This code is pretty much deprecated.

The question I'm asking for, is if there is a place or script you could recommend me that handles something similar to the above. Something like
CSS
pushState
script with AJAX that have pages loading in a div, whereas I don't have to update that page everytime I want to make a change to the navigation etc.

Hopefully you guys understand what I mean.
Posted
Comments
Nitij 3-Feb-15 2:54am    
If I am understanding you correctly, you need to load html content in a div dynamically using Ajax?
[no name] 5-Feb-15 22:31pm    
Exactly. Something up to date, that'll make content easier to load in a single div.

1 solution

If you simply want to set the html of a container when any event is raised then simply set the innerHtml or use $(element).html().

If you are looking to load html from external file, then here is a non-jQuery solution:

C#
function LoadHtml(path, div) {
        var xmlhttp;
        if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
            xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
        }
        xmlhttp.onreadystatechange = function ()
        {
            if (xmlhttp.readyState == 4 &amp;&amp; xmlhttp.status == 200)
            {
                div.innerHtml = xmlhttp.responseText;
            }
        }
        xmlhttp.open('GET', path, true);
        xmlhttp.send();
    }


and the equivalent jQuery code:
$.get( path ).then(function(data){ $(div).html( data ) });


Regards
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900