How to load blade or php content into a view via ajax/jquery in laravel?

0 votes
I am trying to dynamically load content in a view using ajax requests. I know this can be done if you are using html elements e.g. ("#div_place").html(<p>...). The problem lies when I would like to load some php/blade objects into a div for instance. Is this possible or is there a different way to go about achieving the result I want.
Apr 14 in Laravel by kartik
• 11,290 points
297 views

1 answer to this question.

0 votes

Hello @kartik,

Assuming you're using jQuery...

  1. create a route that will respond to the AJAX call and return an HTML fragment

    Route::get('test', function(){
    
        // this returns the contents of the rendered template to the client as a string
        return View::make("mytemplate")
            ->with("value", "something")
            ->render();
    
    });
  2. in your javascript:

    $.get(
        "test",
        function (data) {
            $("#my-content-div").html(data);
        }
    );

Thank You!!

answered Apr 14 by Niroj
• 22,790 points

Related Questions In Laravel

0 votes
1 answer

How to check request is ajax or not in Laravel?

Hello, Laravel allow use of their library method that ...READ MORE

answered Mar 23 in Laravel by Niroj
• 22,790 points
58 views
0 votes
1 answer

How to identify wheather the request is HTTP GET or HTTP POST in Laravel?

Hey, In order to identify the type of ...READ MORE

answered Mar 19 in Laravel by Niroj
• 22,790 points
40 views
0 votes
1 answer

How to mock a static facade methods in Laravel?

Hey, Facades provide a "static" interface to classes ...READ MORE

answered Mar 19 in Laravel by Niroj
• 22,790 points
111 views
0 votes
1 answer

How to delete or clear caching in Laravel?

Hey @kartik, There are many commands to clear ...READ MORE

answered Mar 20 in Laravel by Niroj
• 22,790 points
64 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 947 views
0 votes
0 answers
0 votes
1 answer

How to include a sub-view in Blade templates in Laravel?

Hello @kartik, You can use the blade template ...READ MORE

answered Mar 31 in Laravel by Niroj
• 22,790 points
216 views
0 votes
1 answer

How to break a for each loop in laravel blade view?

Hello @kartik, By default, blade doesn't have @break and @continue which are ...READ MORE

answered Apr 6 in Laravel by Niroj
• 22,790 points
201 views