≡ Menu

xmlhttp and some code

A late night post on xmlhttp… Who would have thought that something so interesting would come out of my mind at 2:00 AM? Maybe that’s why we don’t always get interesting stuff here… Wow though, who would have though javascript had that power?

Ok, so none of you have a clue what I’m talking about, with the exception of those who happen to speak to me tonight after I discovered it. It’s this block of javascript:

var mystring="id=true&blah=false";
var xmlhttp=false;
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;

if (!xmlhttp && typeof XMLHttpRequest!=\’undefined\’) {
xmlhttp = new XMLHttpRequest();

xmlhttp.open("POST", document.location.href,false);
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");

I know many of you don’t speak javascript, but here’s what that says: Post some variables, without reloading the page, and then do something with what you get back. That means you could, in theory… have 1 static html page, 1 dynamic php document (that perhaps only returns some text), and you could have a page that never reloads (at least not in the browser sense) but could still be navigated. A very interesting idea…. Something that flash is really good at.

Of course, this brings back the downside that you can’t bookmark anything, but still… I can see how they do credit card pending pages now. It all makes sense.

Ok, I know I’m not talking much about it… Just try it out if your a programmer and see what happens :-). Take note of mystring and the last alert. If you need it to post to something else, take a look at the open line.

Ok, that’s all I have to say… Finals week is pending.