Laravel @include a blade view via ajax Laravel @include a blade view via ajax laravel laravel

Laravel @include a blade view via ajax


You want something like

$(document).ready(function() {    $("#tab1").click(function() {        $.ajax({            type: 'POST',             url : "/yourrouteview",             success : function (data) {                $("#tab1").html(data);            }        });    });}); 

Your controller and route must configure /yourrouteview to get the correct view (that is @include('price.blade.php')


Make your ajax request and return the view from controller function like:

return view('your_view');

in ajax success function, append it to where you want like:

success: function(response){    $('#Id').html(response);}

The flow is something like:

$('#tab').click(function(){    // ajax call here    ...    success: function(response){        $('#Id').html(response);    }});

controller:

function funcName(){    // Do what ever you want    return view('your_view');}


Via ajax request you can get compiled view from server and yield that value into some parent root, e.g in promise .then call.

On the server side you can use simple handler of HTTP request in your routes:

Route::get('/', function () {    return view('price'); // here you can pass params for compiling blade template});