I've created a form that targets an iframe to submit an image. I absolutely had this working previously, but now the whole page submits, instead of just the iframe. I'm at a total loss.
HTML:
<form id="upload-form" name="upload-form" class="" action="/handle/upload" method="post" enctype="multipart/form-data">
<div class="fileinput-wrap">
<label for="fileinput">Image input</label>
<input type="file" name="file" id="fileinput" />
</div>
<input type="submit" id="submitter" name="submitter" />
</form>
JS:
$("#fileinput").on('change', function () {
var $iframe = $("<iframe />").attr({
id: 'frame_uploader',
name: 'frame_uploader'
});
var $img = $("<img />");
var imageUrl = "";
$("#upload-form").prepend($img).append($iframe)
.attr('target', 'frame_uploader')
.trigger('submit');
$iframe.load(function () {
var imageUrl = $iframe.contents().find("body").text();
$img.attr('src', imageUrl);
});
});
http://jsfiddle.net/NVp9K/