Wednesday, June 04, 2014

A poem for 1:23:21 AM

What can I control?

The sun?  The air? Can I ensure that tomorrow comes?
Can I stop death? or the sad lives of unwanted children?
Can I control pain? or guarantee happiness?

I can give my family a safe place to sleep tonight.

Whom can I trust?

My 4th grade teacher, Steve Jobs, Oral Roberts or President Obama?
A newspaper rack or TMZ? The wisdom of crowds? Manufactured celebrities?
Any girl who has whispered in my ear?

I will trust those who truly love me.

What should I believe?

In a God benevolent and omnipresent?  Worlds beyond science?
In a liberal or conservative political vision?  In words from men cleverer than me?
In a hopeful view of humanity?  In pragmatism? In fatalism?
In life?  In Death?

I will err on the side of hope.

Monday, June 02, 2014

Using FormData correctly

Using FormData to upload images via Ajax is easier than most examples you find on the Internet make it.  Just define your form in HTML, include as many files as you want, then pass the document element of the Form to the constructor of the FormData class.

Most examples in the wild suggest something like this:

var data = new FormData();
jQuery.each($('#file')[0].files, function(i, file) {
    data.append('file-'+i, file);

If your form is defined in your HTML, it is easier to pass the form into the constructor than it is to iterate and add images.
$('#my-form').submit( function(e) {

    var data = new FormData(this); // this is the form element

            url: '/my_URL/',
            data: data,
            cache: false,
            contentType: false,
            processData: false,
            type: 'POST',     
            success: function(data){