<html> <body> <script> $main_catogery = sessionStorage.getItem('main_cat_name'); switch ($main_catogery) { case "essentials": include('sub-catogery-design.essentials'); //@include('sub-catogery-design.essentials'); //alert("essentials"); break; case "electronics": //alert("electronics"); break; } </script> </body> </html>
I need to call the external .blade file inside my main .blade file switch statement, I alrady used ‘include’ but it’s not worked inside the script tag anyone can help me to do this..?
Advertisement
Answer
<html> <body> <div id="main_cat_data"></div> <script> $sessionData = sessionStorage.getItem('main_cat_name'); const xhr = new XMLHttpRequest(); const container = document.getElementById('main_cat_data'); xhr.onload = function(){ switch ($sessionData) { case 'essentials': container.innerHTML = xhr.responseText; break; case 'electronics': container.innerHTML = xhr.responseText; break; } }; switch ($sessionData) { case 'essentials': //'view_essentials' my route for view blade file xhr.open('get', 'view_essentials'); break; case 'electronics': xhr.open('get', 'view_electronics'); break; } xhr.send(); </script> </body> </html>
I solved my problem, thanks to those who help me.