skip to Main Content

In my HTML page, I have a modal :

<div class="modal fade"> 
.....
    <div class="modal-body" id="{{ modalId ~ 'Body' }}">
         **** I want load HTML with Ajax here ********************
    </div>
</div>

I want to load HTML dynamically with ajax in my modal body, like this :

$.ajax({
   url: Routing.generate('XXXXXXXXX', {'id' : $(this).data('id')}),
   type: 'GET',
   async: true,
   success: function (data) {
       $('#modalViewMailBody').html(data);
   }

});

My problem is that the data (html) returned contains CSS and another html, head and body tags.

It creates conflicts and impacts the visual of the base screen.

Any ideas to escapte this problem ?

Thank you in advance.

2

Answers


  1. Create an endpoint in the controller and call it via the ajax function. You have to return the twig file in the controller method which will be used in your ajax function success response.

    Login or Signup to reply.
  2. In ajax please add dataType: "html" hope so your problem solve using this. full ajax look like bellow 
    $.ajax({
       url: Routing.generate('XXXXXXXXX', {'id' : $(this).data('id')}),
       type: 'GET',
       async: true,
       dataType: "html" ,
       success: function (data) {
           $('#modalViewMailBody').html(data);
       }
    });
    

    });

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search