首先,我们需要设置一些路线.您也可以使用控制器执行此操作.
Route::get('home', function()
{
return View::make('home');
});
Route::get('someRoute', function()
{
return View::make('someView');
});
对于主视图,我将添加一个脚本部分:
//home.php
$('a.ajax').click(function(e){
e.preventDefault();
var pageURL = $(this).attr('href');
$('#ajaxContent').load(pageURL);
});
如果您正在使用刀片模板,这是一个实现
//main.blade.php
@yield('styles')
@yield('content')
@section('scripts')
@show
//home.blade.php
@extends('main')
@section('content')
@stop
@section('scripts')
@parent
$('a.ajax').click(function(e){
e.preventDefault();
var pageURL = $(this).attr('href');
$('#ajaxContent').load(pageURL);
});
@stop