First we need to configure some routes. You can also do this using controllers.
Route::get('home', function() { return View::make('home'); }); Route::get('someRoute', function() { return View::make('someView'); });
In the home view, I would add a scripting section:
//home.php <html> <head> <script> $('a.ajax').click(function(e){ e.preventDefault(); var pageURL = $(this).attr('href'); $('#ajaxContent').load(pageURL); }); </script> </head> <body> <div class="wrapper"> <a href="{{URL::to('someRoute')}}" class="ajax">Click Here</a> <div id="ajaxContent"></div> </div> </body> </html>
If you use blade standardization, an implementation is implemented here
//main.blade.php <html> <head> @yield('styles') </head> <body> <div class="wrapper"> @yield('content') </div> @section('scripts') <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script> @show </body> </html> //home.blade.php @extends('main') @section('content') <a href="<?=URL::to('someRoute')?>" class="ajax">Click Here</a> <div id="ajaxContent"></div> @stop @section('scripts') @parent $('a.ajax').click(function(e){ e.preventDefault(); var pageURL = $(this).attr('href'); $('#ajaxContent').load(pageURL); }); @stop
source share