0

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.

This is my modal.php file on view side.

<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:

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?

Tatu Bogdan
  • 586
  • 2
  • 10
  • 27

2 Answers2

0

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. For this you can use Bootstrap Modal, Jquery UI Dialog etc.

Bootstrap Modal

Jquery UI Dialog

Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59
0

You can use: How do I promisify native XHR?

Which this function can centralise all your AJAX requests, your .htaccess call the file (controller) and this call the model. 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.

Oz-rod
  • 31
  • 1
  • 6
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - [From Review](/review/late-answers/31837199) – Sumit Sharma May 27 '22 at 12:18