亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將 ajax 響應的輸出放在 codeigniter 的模態 iframe 中

如何將 ajax 響應的輸出放在 codeigniter 的模態 iframe 中

阿波羅的戰車 2023-05-11 16:00:51
我有一個 codeigniter 項目。在我看來,我有一個模態。單擊按鈕時,模態啟動并調用上面的函數。它執行 ajax 調用以創建 html 頁面并將其輸出為調用的響應。這樣可行?,F在我需要獲取此響應并將其顯示到 iframe 中。我的嘗試失敗了。我做錯了什么或我必須以哪種方式做錯?背景:我想使用 html 代碼進行預覽,該代碼將視圖文件中的靜態代碼與 ajax 調用的兩個給定字段相結合。這些頁面有自己的 CSS 樣式。所以我需要使用 iframe 來準備沒有其他 css 樣式發生沖突。也許有更簡單的方法嗎?模態:撰寫 ×                <div class="row" id="preview_area">                    <iframe id="preview_frame" class="col-lg-12 col-md-12 col-sm-12" src=""></iframe>                </div>              </div>              <div class="modal-footer">                <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>                <button type="button" class="btn btn-primary">Save changes</button>            </div>          </div><!-- /.modal-content -->      </div><!-- /.modal-dialog -->  </div><!-- /.modal -->功能:$('#launchbutton_modal_preview').on('click',function(e){             event.preventDefault();        $.ajax({            type: "POST",            url: "<?= site_url(); ?>myurl/my_view/",            data: {                <?php echo $this->security->get_csrf_token_name(); ?> : '<?php echo $this->security->get_csrf_hash(); ?>',                head : $('input[name=subject]').val(),                content : $('.textarea').val(),            },                      success: function(response) {                console.log(response);                    if(response != ''){                        alert("response",response);                        getIframeDocument($('#preview_frame')).body.update(response);                        var iFrame = $('<iframe id="thepage"></iframe>');                                                    var iFrameDoc = iFrame[0].response || iFrame[0].contentWindow.document;                        iFrameDoc.write('<p>Some useful html</p>');                        iFrameDoc.close();                        $('#preview_area').html(iFrame);                                            }                }        });             });
查看完整描述

1 回答

?
慕田峪4524236

TA貢獻1875條經驗 獲得超5個贊

經過幾個小時的測試后,我找到了一種安靜簡單的方法來做我想做的事情。


  //Add iframe with the responsepage to modal

$('<iframe id="preview_frame" class="col-lg-12 col-md-12 col-sm-12 p-0" style="position:relative;top:0px;width:100%;height:75vh;border: 1px solid #e9ecef;" src=""></iframe>')

   .appendTo('#preview_area')

   .on('load', function(){

        $(this).contents().find('body').append(response);   

});


查看完整回答
反對 回復 2023-05-11
  • 1 回答
  • 0 關注
  • 140 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號