Why is this form not submitting inside the target iframe?

℡╲_俬逩灬. 提交于 2019-12-08 04:50:21

问题


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/


回答1:


I read somewhere that certain iframe names are reserved. Changing the name of the iframe has fixed the problem.




回答2:


Maybe you should add frame id and name attribute when it is created. Just like this:

var $iframe = $("<iframe id=\"frame_uploader\" name=\"frame_uploader\" />");


来源:https://stackoverflow.com/questions/14882259/why-is-this-form-not-submitting-inside-the-target-iframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!