我在jquery中提交表单,其响应在iframe中打开,这是PDF现在我想打开iframe作为对话框请帮我下面是我的代码

时间:2014-09-25 18:18:42

标签: jquery html iframe

这是我的js部分

function openFiles(fileSlNo){

document.forms[0].method = "POST";
document.forms[0].target = "test";
document.forms[0].action = "folderNavigation.do?pageMode=DOWNLOAD_FILE&fileSlno="
        + fileSlNo;
document.forms[0].submit();

}

<div id="content">
          <iframe id="displayframe" name="test"></iframe> 
    </div>

请告诉我怎么做?提前致谢

1 个答案:

答案 0 :(得分:0)

根据描述&amp;评论,您正试图将一些参数发布到服务器&amp;作为回应,您需要提供PDF的路径。

以下是代码:

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>

<div id="showDialog" title="Your Dialog Title Here" style="display: none;">

</div>
<form name="frmDemo" action="" method="post">
<input type="text" id="fileSlNo" name="fileSlNo" />
<input type="submit" value="Show Dialog" />
</form>

<script type="text/javascript">
$(function(){

    $('form').submit(function(event){
        event.preventDefault();
        var fileSlNo = $('#`').val();
        var data     = { pageMode: 'DOWNLOAD_FILE', fileSlno: fileSlNo };
        $.ajax({
            type: POST, 
            url:, 'folderNavigation.do',
            data: data,
            success: function(responseData){
                // supposing responseData is the url of PDF
                $('#showDialog').dialog('destroy'); 
                $('#showDialog').html('<iframe src="'+responseData+'"></iframe>').dialog({
                    height:400,
                    modal: true
                });
            }       
        });

    });

});
</script>