在codeigniter中使用 AJAX 加载模态对话框

x8diyxa7  于 2022-12-07  发布在  其他
关注(0)|答案(2)|浏览(124)

我正在使用codeigniter php(MVC框架),我想在点击按钮时打开一个模态对话框,但我的问题是,我的模态只出现在我的响应网络(预览)中,而不是在我的实际屏幕上。
这是我在视图端的modal.php文件。

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body">
        ...
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>

这是我的控制器指向的那个观点:

public function showmachinelist() {
        $this->load->view('monitor/modal');

    }

我在js中有这个按钮来触发我 AJAX :

button_2: "<button type=\"button\" class=\"getid btn btn-default tara\" data-target=\"#myModal\" data-toggle=\"modal\" data-id=\""+ missedEntry.id +"\" >Select</button>"

还有这个 AJAX :

$.ajax({
    type: "POST",
    url: "Monitor/showmachinelist",
    data: {'val' : imagename},
    dataType: "text"
    }).done(function(data) {
   console.log("test2");
   }).fail(function() {
alert( "error" );
});

我怎么能做出那样的情态呢?

tvmytwxo

tvmytwxo1#

你的ajax返回一些html,你必须把html放到一个div中,然后把div变成popup或者modal或者dialog。为此你可以使用Bootstrap ModalJquery UI Dialog等等。
Bootstrap Modal
Jquery UI Dialog

ac1kyiln

ac1kyiln2#

您可以用途:How do I promisify native XHR?
这个函数可以集中你所有 AJAX 请求,你的.htaccess调用文件(控制器),这个调用模型。结果,可能是一个文本信息或数据组(转换成JSON格式)将用于显示在页面或移动到新的页面,等等。

相关问题