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

+1 vote
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, 2020 in Laravel by kartik
• 37,520 points
27,956 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, 2020 by Niroj
• 82,840 points

Related Questions In Laravel

0 votes
1 answer
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, 2020 in Laravel by Niroj
• 82,840 points
13,130 views
0 votes
1 answer

How to call a controller function inside a view in laravel 5

Hello @kartik, Just try this in your view ...READ MORE

answered Sep 25, 2020 in Laravel by Niroj
• 82,840 points
8,418 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, 2020 in Laravel by Niroj
• 82,840 points
3,291 views
0 votes
2 answers
+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 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,434 views
0 votes
1 answer
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, 2020 in Laravel by Niroj
• 82,840 points
15,186 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, 2020 in Laravel by Niroj
• 82,840 points
13,406 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP