php - Loading laravel view with ajax -
i new web development.i using laravel app used blade templates creating pages.i have main blade in header , footer exist , using wrapper.i want of other pages open in without reloading base template , when open page extends main wrapper new view correctly when update page's content ajax content of page doubles footer may because @includes() creates new page within existing 1 want fix double content , footer.please help!here code of pages used load within main wrapper
@extends('wrappertemplate') @section('content') <div class="body-content">` , content here </div> @stop
i advise unless it's simple use case/playground exercise, don't way, , instead define proper api using laravel, use front end framework react, angular, ember etc etc. interact api , handle dom manipulation/creation. seems v bizarre re-render entire page using html loaded of ajax. there plenty of tutorials on using laravel , various front end frameworks
however, asked, need first create page extends wrappertemplate have. should load without content in body
then create blade file has html want - shouldn't extend anything. have route , controller method returns contents of file.
then have html on ajax , append body.
this sample controller:
class pagecontroller extends controller { // method renders page wrapper public function home() { return view('pages.home'); } // route returns partial, i.e. content gets refreshed public function content() { $html = view('partials.home-content')->with(['name'=>'exoticchimp'])->render(); return response->json(['html' => $html]); } }
then views:
<!--pages.home--> @extends('wrappertemplate') @section('content') <div class="body-content">` , content here </div> @stop <!--partials.home-content--> <h1>hello {{$name}}</h1>
then you'd append html parameter in response body-content using basic jquery or js. i'm not going write js well, google making ajax requests using jquery , there ton of articles on stuff. must stress though should using laravel + front end framework.
tutorial: http://culttt.com/2015/04/06/getting-started-with-laravel-and-ember/
you should read on laravel documentation controllers. http://laravel.com/docs/5.1/controllers
Comments
Post a Comment