Update your DOM with JSON from the server

Ajax calls which render HTML from the server can sometimes get hard to manage. This little module will take JSON from your server and render it with a template that’s already in your HTML. I’ll explain it more later. You’ll need to be using TopClass.

PM.JsonUpdater = TopClass({
publicMethods: {
update: function(theElement, theJson) {
element = $(theElement);
createTemplate();
removePreviousContentIfExists();
insertNewContent(theJson);
removeLoader();
},
updateFromUrl: function(url, theElement) {
new Ajax.Request(url, {method: 'get', onComplete: function(response) {
var theJson = response.responseText.evalJSON();
PM.JsonUpdater.update(theElement, theJson);
}});
}
},
privateMethods: {
element: null,
template: null,
createTemplate: function() {
templateElement = element.down(".template");
templateHTML = "

\n” + templateElement.innerHTML + “\n
\n”;
template = new Template(templateHTML);
},
removePreviousContentIfExists: function() {
if(defined(element.down(”.pm_inserted_content”))) {
element.down(”.pm_inserted_content”).remove();
}
},
insertNewContent: function(theJson) {
new Insertion.Top(element, template.evaluate(theJson));
},
removeLoader: function() {
element.down(”.pm_loader_element”).remove();
}
}
});

One Response to “Update your DOM with JSON from the server”

  1. Anonymous Says:

    Office 2007 Professional
    Office 2007 Ultimate
    Office Professional 2007
    Office Ultimate 2007
    MS Office 2007

Leave a Reply

Logged in as . Logout »