What I am trying to do is write an endpoint that returns an html and then insert it in another html using Jquery, something like this:
I have a page that have a button, when I click it a ajax request is sent to my controller and I want that controller to render a Twig template and then return it in a html form, then back in my done ajax function, using jquery, insert the html value from that request into a dom element with an specific id.
What I have tried is this
<div class="" id="result"></div>
This is how I send the request
$.ajax({
method: "POST",
url: "{{ path('my_controller') }}",
}).done(function (res) {
console.log("Res", res)
$("#result").html(res);
}).
And this is my controller code
public function renderAction () {
$params = [
"message" => "Lorem ipsum wea"
];
return $this->render('format.html.twig', $params);
}
format.html.twig
doesnt have anything special yet, it just prints the message
param
It kinda works but my controller sends me back an error twig html that says
Failed to start the session because headers have already been sent by "" at line 0.
That error page is inserted where the #result element is.
What am I doing wrong?