views:

41

answers:

2

It's working in all other browsers, and it was working on IE8 before, but I did some code cleanup and moved some things around, and now its submitting this form to it's self. It's an "ajax" uploader (yes, not really ajax, but you know what I mean)

Here is the JS:

function file_upload($theform,item_id){
    $theform.attr('ACTION','io.cfm?action=updateitemfile&item_id='+item_id);
    if($theform.find('[type=file]').val().length > 0){
        $('iframe').one('load',function(){
            $livepreview.agenda({
                action:'get',
                id:item_id,
                type:'item',
                callback:function(json){
                    $theform.siblings('.upload_output').append('<li style="display:none" class="file-upload"><a target="blank" href="io.cfm?action=getitemfile&item_file_id='+json[0].files.slice(-1)[0].item_file_id+'">'+json[0].files.slice(-1)[0].file_name+'</a> <a style="color:red" title="Delete file?" href="#deletefile-'+json[0].files.slice(-1)[0].item_file_id+'">[X]</a></li>').children('li').fadeIn();
                    $theform.siblings('.upload_output').find('.nofiles').remove();
                }
            });
            //Resets the file input. The only way to get it cross browser compatible as resetting the val to nothing
            //Doesn't work in IE8. It ignores val('') to reset it.
            $theform.append('<input type="reset" style="display:none">').children('[type=reset]').click().remove();
        });
    }
    else{
        $.alert('No file selected');
        return false;
    }
}
/* FILE UPLOAD EVENTS */
//When they select "upload" in the modal
$('.agenda-modal .file_upload').live('submit',function(event){de
    file_upload($('.agenda-modal .file_upload'),$('.agenda-modal').attr('data-defaultitemid'));
});

If you didn't know, ACTION has to be capitalized for Firefox to work. Also, i know for sure it's submitting to it's self because the iframe shows the current page inside of it's self and all the scripts get loaded again. Also, in the .live(), adding return false; does nothing.

Here is the HTML just in case:

        <label>Add Attachment</label>
        <form class="file_upload" method="post" enctype="multipart/form-data" target="upload_target" action="">
            <input name="binary" id="file" size="27" type="file" /><br />
            <br><input type="submit" name="action" value="Upload" /><br />
            <iframe class="upload_target" name="upload_target" src="" style="display:none"></iframe>
        </form>
        <label>Attachments</label>
        <ul class="upload_output">
        <li class="nofiles">(No Files Added, Yet)</li>
        </ul>
A: 
Pointy
returning false makes the entire form not submit for me. It's still has to submit, just to the iframe...
Oscar Godson
Actually, you helped me and told me not too submit :) http://stackoverflow.com/questions/3367147/ajax-upload-issues-with-jquery
Oscar Godson
Ha ha! I thought your username sounded familiar :-) OK I'm still looking and scratching my head a little ...
Pointy
Yeah, you've helped me out a few times. and good catch on that weird Firefox thing... seems strange it'd confuse the browser. But it's good to know.
Oscar Godson
ok I updated my answer again, and I apologize if it's another wrong guess
Pointy
oh and back on that old question, the `<iframe>` had an "id" value according to the code you posted - here it's a class. You can have it be the same for "class", "name", and "id" of course.
Pointy
ok ill try it out, i have a meeting in 5 mins, but when i get back ill check.
Oscar Godson
So i changed the form to also have an ID of upload_target as well as changed my jQuery selector to select #upload_target rather than .upload_target, but still, no go. :( I hope i can fix this in IE8 as thats what the City Council here is on...
Oscar Godson
OK, this is weird... if i make a button that has a click event of $(form).submit(), then it works in IE, but the "submit" event wont go off when i click the submit button...
Oscar Godson
Wait what jQuery selector references "upload_target"? I don't see that in any of the code. The `<form>` tag's "target" should be just plain "upload_target".
Pointy
Hmm? Sorry, not following you, The form's tag target does reference "upload_target"? The HTML above: <form class="file_upload" method="post" enctype="multipart/form-data" target="upload_target" action="">
Oscar Godson
Right - good. I was just confused. Well the IE8 debugger, unlike the IE6 and 7 debugger, is actually pretty good. Maybe you can get some help from it.
Pointy
A: 

It is supposed to send the form to itself.

Consider that the button is of type submit (ie submits form automatically) and that the form action is empty (ie, send it self).

However, as you've correctly done, a submit handler may cause the form to not submit at all (to which I ask, what was the point of submitting in the first place? But that's past the point)

Anyway, you should stop event propagation and return false in your event handler.

Christian Sciberras
If the handler returns `false`, jQuery will assume that means for propagation to stop too. There's no reason to do both (though of course it doesn't really hurt anything).
Pointy
just to try it, i added event.stopPropation() at the end of the live event. Nothing happened... the form still submits even on the other browsers.
Oscar Godson
Pointy I've had an issue with that and stopping KeyDown of input text boxes. I would suggest using both.
Christian Sciberras
How about showing the iframe? I've seen issues about hidden iframes not running at all. To fix, remove style="display:hidden;" and make sure frameborder="0", width="1" and height="1"
Christian Sciberras
Hmm, something else must have been modified somehow or someway... The iframe, i un-display:none'd it and when i upload something in FF or Chrome, it doesnt show inside (the JSON return doesn't), but the file is uploaded...
Oscar Godson
OK, this is weird... if i make a button that has a click event of $(form).submit(), then it works in IE, but the "submit" event wont go off when i click the submit button...
Oscar Godson