我是一個新手laravel用戶,並試圖用教程和文檔編寫我的代碼。 當我嘗試打開網站時發生加載動畫,之後,菜單和內容分割到頁面的任一側。 我只想點擊菜單按鈕時更改內容分區。您可以優化我的路線和ajax請求嗎?(php/laravel)
這些都是我的routes.php文件:
Route::controller(Controller::detect());
Route::get('articles', array('uses'=>'[email protected]'));
Route::get('articles/(:any)', array('as'=>'article','uses'=>'[email protected]'));
Route::get('abouts', array('as'=>'abouts','uses'=>'[email protected]'));
這是我default.blade.php菜單部分:
<div id="sidebar-content">
<ul id="menu">
<li class="current"><a href="<?php echo URL::to('articles'); ?>">ANASAYFA</a></li>
<li><a href="<?php echo URL::to('abouts'); ?>">HAKKIMIZDA</a></li>
</ul>
</div>
是正確的鏈接在這裏?
我ajax.js
$(document).ready(function() {
$("#sidebar-content ul li a").click(function(e){
e.preventDefault();
$('#content').load(this.href);
console.log('This href =='+this.href);
return false;
});
});
當我點擊鏈接,我得到一個加載動畫,且未顯示的內容。
這是我的文章控制器:
class Articles_Controller extends Base_Controller {
public $restful = true;
public $layout = 'layouts.default';
public function get_index(){
$this->layout->title = "Anasayfa";
$this->layout->content = View::make('articles.index')->with('articles',Article::order_by('id')->get());
}
}
這些都是console.logs:
GET http://localhost/~ytsejam/laravel/public/index.php/abouts jquery.min.js (line 4)
This href ==http://localhost/~ytsejam/laravel/public/index.php/abouts ajax.js (line 6)
GET http://localhost/~ytsejam/laravel/public/js/basic.js?_=13446 jquery.min.js (line 4)
GET http://localhost/~ytsejam/laravel/public/index.php/abouts jquery.min.js (line 5)
This href ==http://localhost/~ytsejam/laravel/public/index.php/abouts ajax.js (line 6)
GET http://localhost/~ytsejam/laravel/public/index.php/abouts jquery.min.js (line 5)
This href ==http://localhost/~ytsejam/laravel/public/index.php/abouts jquery.min.js (line 7)
你能幫助我嗎?
動畫加載。所以在頁面分裂到每一面之後。這是我想要的方式,我不希望每次單擊鏈接時都要重新加載頁面。 – ytsejam 2012-08-12 17:33:10