It is hard for some people to accept that some of the simplest recipes are classics because you really can’t improve on them. Take the pancake for instance. Nothing beats the classic lemon and sugar. You can faff about with all sorts of stuff but you are just tinkering for the sake of tinkering; over complicating things. Something delicious can be that simple it doesn’t need expensive and obscure ingredients. As long as the lemon is real and not out of plastic and the sugar is soft and dark brown… enjoy
Guess what we had for dinner tonight?
I found “My cat likes to hide in boxes” by Eve Sutton in a secondhand bookshop. This proved to be a great source of fun. My four year old daughter delights in looking for each place in her Atlas as we go through the book.
“The cat from France…”, “Lets find France, it’s in Europe.” so she looks at the contents page to find Europe, then we find France. Even better both the Atlas and the book have a picture of the Eiffel Tower so we go and look at the picture of Mummy and Rachel (her godmother) standing in front front of it with 287 days to go before year 2000.
You realise that you haven’t been blogging enough when the last day that you posted anything falls off the stats graph! So here I am adding my iota to the smoke and mirrors that is Ajax.
There I was wanting to POST data using Ajax. So I read my text books and adapted what I found then Googled to fill in the gaps. It worked in Firefox – hurrah! Then I tried IE6, and waited … after the counting stopped it finally deigned to update – hurroo! So I started removing lines to see if it still worked and if the speed would improve. This is what was left after the dust cleared:
function updateStuff() {
setUpdateStuffString();
makeUpdateStuffRequest("stuffupdate-ajax.php");
}
var updateStuffString;
function setUpdateStuffString () {
updateStuffString="";
var tempString = "";
var frm = document.StuffDetails;
var numberElements = frm.elements.length;
for(var i = 0; i < numberElements; i++) {
switch (frm.elements[i].type) {
case 'select-one':
tempString=frm.elements[i].name+"="
tempString+=encodeURIComponent(frm.elements[i].options[frm.elements[i].selectedIndex].text);
break;
case 'radio':
if (frm.elements[i].checked) {
tempString=frm.elements[i].name+"="+encodeURIComponent(frm.elements[i].value);
}
break;
submit:
tempString="Submit="+encodeURIComponent(frm.elements[i].value);
break;
default:
tempString=frm.elements[i].name+"="+encodeURIComponent(frm.elements[i].value);
break;
}
if(i < numberElements-1) {
updateStuffString +=tempString+"&";
}
else {
updateStuffString += tempString;
}
}
}
var http_request_updateStuff = false;
function makeUpdateStuffRequest(url) {
http_request_updateStuff = false;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
http_request_updateStuff = new XMLHttpRequest();
if (http_request_updateStuff.overrideMimeType) {
http_request_updateStuff.overrideMimeType('text/xml');
// See note below about this line
}
}
else if (window.ActiveXObject) { // IE
try {
http_request_updateStuff = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
http_request_updateStuff = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
}
}
}
if (!http_request_updateStuff) {
alert('Giving up; cannot create an XMLHTTP instance');
return false;
}
http_request_updateStuff.onreadystatechange = alertUpdateStuff;
http_request_updateStuff.open('POST', url, true);
http_request_updateStuff.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
destinationDiv = document.getElementById("editstuff");
destinationDiv.innerHTML="Updating details...";
http_request_updateStuff.send(updateStuffString);
}
function alertUpdateStuff() {
if (http_request_updateStuff.readyState == 4) {
if (http_request_updateStuff.status == 200) {
destinationDiv = document.getElementById("editstuff");
destinationDiv.innerHTML=http_request_updateStuff.responseText;
...
}
else {
alert('There was a problem with the request.');
}
}
}
Of course you may find that there are other elements that I haven’t used that need special treatment that the default case can’t cope with but that’s your fun!