Daily Archives: November 22, 2007

Why won’t my AJAX form upload a file?

Do you ever have those dumb moments? You waste a whole load of time trying to get a piece of code to work and performing the most complex de-bugging on it only to realise that you have overlooked the most basic and obvious thing?

Yesterday I was putting together an image upload script, which I wanted to do with AJAX. I wanted to have a file upload box at the top of the screen, press upload, have a nice spinning graphic whilst it uploaded, and then have the image fade into a gallery below. I tried all the AJAX methods with Mootools, checked and double checked my form enctype, until it dawned on me…

When you submit forms via AJAX, then it runs through Javascript (that’s all AJAX is of course). The Javascript takes the content of the form boxes and then sends it through an AJAX request. What Javascript cannot do is access local files on your machine, which is why a file upload field on an AJAX form will not work.

D’oh! I couldn’t believe I’d been so stupid. I put it down to the excessive hours I’ve been working…

Anyway, how about a simple workaround?

Put an IFRAME on the page with invisible borders and load up a file in that. Works perfectly, and although the page in the frame is reloading, it doesn’t appear to be at all. End result is exactly what I wanted and very simple.

Should Beckham retire?

Not if last night’s performance was anything to go by. After Peter Crouch, Becks was our best player. He proved yet again that he is the guy for the big occasions. And what was all that nonsense in the BBC studio about him not being fit? He covered 6.4KM in the time he was on the pitch – more than anyone else in the same 45 minute period.

The MLS doesn’t seem to have done him much damage. Yet.

Let’s hope he can keep it up until 2010 because I don’t see anyone able to fill his shoes yet.

Bye bye Steve

Steve McLaren has been sacked. Thank goodness for that. The England team deserves better.

Shambolic England – time for Steve McLaren to go

I’ve blogged before that Steve McLaren should be sacked and tonight was the ultimate proof. There are people all over the forums claiming that there are too many foreigners in the English game and this has caused the current crisis. There are too many foreign players, and it will have an impact, but there are still sufficient numbers of talented players to choose from. Read more »