我有一個 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); } } }); });
如何將 ajax 響應的輸出放在 codeigniter 的模態 iframe 中
阿波羅的戰車
2023-05-11 16:00:51