简体   繁体   English

在 codeigniter 中使用 ajax 加载模式对话框

[英]Load a modal dialog with ajax in codeigniter

I'm using codeigniter php (MVC framework) and I want to open a modal dialog when clicked a button, but my problem is that my modal appears only in my response network(in preview) and not on my actual screen.我正在使用codeigniter php(MVC框架),我想在单击按钮时打开一个模式对话框,但我的问题是我的模式只出现在我的响应网络中(预览中)而不是我的实际屏幕上。

This is my modal.php file on view side.这是我在视图端的 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>

This is my controller to point to that view:这是我的控制器指向该视图:

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

    }

And I have this button in js to trigger my ajax:我在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>"

And this ajax:而这个阿贾克斯:

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

How I can make show that modal?我怎样才能显示那个模态?

Your ajax returns you some html, you have to put that html into a div and make that div a popup or modal or dialog .您的ajax会返回一些 html,您必须将该 html 放入div并使该div成为popupmodaldialog For this you can use Bootstrap Modal , Jquery UI Dialog etc.为此,您可以使用Bootstrap ModalJquery UI Dialog等。

Bootstrap Modal引导模式

Jquery UI Dialog jQuery UI 对话框

You can use: How do I promisify native XHR?您可以使用: 我如何承诺原生 XHR?

Which this function can centralise all your AJAX requests, your .htaccess call the file (controller) and this call the model.这个函数可以集中你所有的 AJAX 请求,你的 .htaccess 调用文件(控制器),这个调用模型。 The result, maybe a text information or groups of data (transform it to JSON format) will use to show in page or to move to new page, etc.结果,可能是文本信息或数据组(将其转换为 JSON 格式)将用于在页面中显示或移动到新页面等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM