Do you have a serializer in your user entity? Because you are getting all users as entities. I suggest you to do something like this:
When you click a button or any element, call your route like this:
//change this element to your button
$('a.press-me').click(function() {
$.ajax({
url: 'YOUR ROUTE HERE',
dataType: 'HTML',
success: function (data) {
$('#your-div').html(data);
}
});
});
//create a view users.html.twig or something like that...
{% if users is defined and users is not empty %}
{% for user in users %}
Name: {{ user.name }}
{% endfor %}
{% else %}
<p class="error">No data!</p>
{% endif %}
//add this line to top of your controller
use Symfony\Component\HttpFoundation\Request;
//add request variable to your action
public function printAction(Request $request)
{
//you want to get users via ajax right? so check if the request is ajax or not
if($request->isXmlHttpRequest()) {
// Get all users
$users = $this->getDoctrine()->getRepository('ModelBundle:Users')->findAll();
//render a view and pass it as variable
return $this->renderView('ModelBundle:Default:users.html.twig', ['users'] => $users);
}
}