Short Ajax Script

AJAX - it

I wanted to see how small you could make a fully functional AJAX script that worked cross-browser and degraded gracefully, so I went through an old custom AJAX script and made it as small as I possibly could. In the resulting AJAX scripts, the post version is 410 characters and the GET version is only 359 characters long. The scripts are fully functional and accept the following parameters: URL, DATA (in string form), and ELEMENT (to update).

The scripts could be a little smaller, but it would really kill readability.

“Get” AJAX Script

function a(l,d,u){
try{r = new XMLHttpRequest();}catch(e){try {r = new ActiveXObject('Msxml2.XMLHTTP');}catch(e){r = new ActiveXObject('Microsoft.XMLHTTP');}}
if(r){
r.onreadystatechange = function() {if (r.readyState == 4 && r.status == 200){document.getElementById(u).innerHTML = r.responseText;}}
r.open('GET', l+'?'+d, true);r.send(d);
}
}

“Post” AJAX Script

function b(l,d,u){
try{r = new XMLHttpRequest();} catch(e){try {r = new ActiveXObject('Msxml2.XMLHTTP');} catch(e){r = new ActiveXObject('Microsoft.XMLHTTP');}}
if(r){
r.onreadystatechange = function() {if (r.readyState == 4 && r.status == 200){document.getElementById(u).innerHTML=r.responseText;}}
r.open('POST', l, true);r.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');r.send(d);
}
}

Combined AJAX Script

This combined script also accepts a fourth parameter ‘p’ that should evaluate true if the data is to be sent by post.

function a(l,d,u,p){
try{r = new XMLHttpRequest();}catch(e){try {r = new ActiveXObject('Msxml2.XMLHTTP');}catch(e){r = new ActiveXObject('Microsoft.XMLHTTP');}}
if(r){
r.onreadystatechange = function() {if (r.readyState == 4 && r.status == 200){document.getElementById(u).innerHTML = r.responseText;}}
if(p){r.open('POST', l, true);r.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');}else{r.open('GET', l+'?'+d, true);}
}
}

Demo: (Sorry but you will have to go to the full page so the JavaScript is loaded.)

Continue reading. »

Equality, the goal not the signpost.

The United States of America has a long history of inequality, from its treatment of Native Americans to women’s rights, it has tended to favor one group over others, but it has attempted to repair the damage it caused. However, even though America is the “land of opportunity,” its formerly oppressed peoples are not equal, but what does it mean to be equal? Is equality the government saying you must have the same number of employees from each arbitrarily defined “race?” Does equality mean that people should be forced to be equal? In examining this issue, one must define equality itself.

There are three forms of equality: equality of outcome, of opportunity, and of perception. Equality of perception is the most basic: it dictates that for people to be equal, each person should be perceived as being of equal worth.

Continue reading. »

David Hume on Morality

David Hume, an 18th century philosopher, stated that morality is based on sentiments rather than reason. He concluded this after he developed his “theory” of knowledge which stated that everything we could know was observable by the senses — he was a naturalistic philosopher. He then looked at situations in which he thought that there was an obvious “wrong” and he tried to identify the “matter of fact” vice in the situation. He immediately found that he could not find the vice within the facts of the situations.

For example, let us examine a boy who steals a toy at a store. A matter of fact about this situation is that a young human male has taken an item from a store. This is what happened. The senses and reason tell us a few other things too: the toy was a plastic squirt gun; the boy used his hands to take the toy; it took only a second for the boy to do this.

Continue reading. »

Byron’s “The Corsair.”

Byron, intentionally or unintentionally, weaves himself into his poetry stamping it with his entire persona. His characters are part of himself; the poems are pieces of his mind; the events are based on experience. Byron’s poetry is an amalgamation of all aspects of Byron. This is truer in some poems than others: some are nearly biographical and others skillfully manipulate other’s perceptions of Byron. His poetry reveals the inner workings of his mind . Because of this, the voices in Byron’s poetry are not just the voices of Byron’s characters: they are the intermingling of the poet with the poem. One of the most pervasive and recognizable aspects of Byronic poetry is the Byronic hero who is a manifestation of parts of Byron’s own personality and thoughts. Byron’s “The Corsair” introduces the most Byronic of Byron’s heroes: Conrad. He then proceeds to emasculate him and proposes Gulnare, a former sex slave, as an alternative hero.

Continue reading. »