In this post, I will show you a trick to avoid refreshing the page after adding data in the database.
This will make you save time and make your Symfony app more dynamic.
So it will look like this
Adding only this code in your twig :
//Your div where you are going to put your content
<div id="test_container">
//Content here
<div/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
function autoReload() {
setTimeout(function() {
$.ajax({
url: 'http://127.0.0.1:8000/yourpage',
success: function(data) {
$("#test_container").load(" #test_container");
}
});
autoReload(); // refresh the page every 5 seconds
}, 5000);
}
autoReload();
</script>
0 Commentaires