Saturday, December 17, 2005

Fun with Python, JavaScript, and AJAX

As I get further and further away from my work on the VSC, I've found that I better keep up with web development technology or I'll fall quickly behind. To this end, I've started building an JSON enabled contact's database for work. I've found that I've been able to learn very quickly using MochiKit, json-py, and CherryPy. MochiKit is great because it allows you to abstract a lot of the garbage you have to worry about using plain JavaScript.

For example, want to grab some data from your backend using JSON?

<!--assume MochiKit is loaded-->
<script type='text/javascript'>
function showData(data) {
replaceChildNodes("userInput", H3(null, data["userFullName"]), "E-Mail: "+data["email"]);
}
function getData() {
d = doSimpleXMLHttpRequest("http://my.backend/user", {userName:getElement("userInput").value});
e = d.addCallback(evalJSONRequest);
e.addCallback(showData);
}
</script>
<input id='userInput' name='userInput' /><input type='button' value='Get User' onClick="getData()" />
<div id="resultBox">
</div>


This horribly rudimentary example would fetch some user data from a backend process and display it inside of the div with id "resultBox". If you've ever manipulated the DOM with JavaScript, or performed XMLHttpRequest operations with JavaScript, you should be able to see the benefits in this code.

Thursday, December 01, 2005

I was standing in a long line at Wal-Mart this evening, because of course, after 10:00pm, they only have 3 cash registers opened. This is very smart of Wal-Mart, considering its a college town, and half of the inhabitants do all of their shopping after 10:00pm... I digress.

I only make this seemingly random observation, because while I was in line at the register, I had one of those cultural introspective moments - you know, where you listen to the conversation around you (noting that at least one jerk is talking loudly into a cellphone as if to say "look it me, I are cool I have an electronic portable talking device!"), look at the gobs of tabloids on the rack next to you, and think to yourself: "what a fucked up society we live in."

EOT