为什么此表单不在目标iframe内提交? [英] Why is this form not submitting inside the target iframe?
本文介绍了为什么此表单不在目标iframe内提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个定位iframe以提交图片的表单。我绝对有此工作,但现在整个页面提交,而不是只是iframe。
HTML:
< ; form id =upload-formname =upload-formclass =action =/ handle / uploadmethod =postenctype =multipart / form-data>
< div class =fileinput-wrap>
< label for =fileinput>图片输入< / label>
< input type =filename =fileid =fileinput/>
< / div>
< input type =submitid =submittername =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('提交');
$ iframe.load(function(){
var imageUrl = $ iframe.contents()。find(body)。text();
$ img.attr ('src',imageUrl);
});
}); b
$ b> http://jsfiddle.net/NVp9K/
解决方案我在某处读某些iframe名称是保留的。更改iframe的名称已解决问题。
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); }); });
解决方案I read somewhere that certain iframe names are reserved. Changing the name of the iframe has fixed the problem.
这篇关于为什么此表单不在目标iframe内提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文