0
我想要做一個單頁的應用程序,我有兩種類型的用戶。內容(儀表板)應根據登錄用戶的類型呈現。
現在,我對laravel和sammy.js都是全新的,我真的不知道如何處理它。處理內容afler登錄
我認爲工作流程應該如下:
- 爲每個用戶類型
- 用戶輸入的登錄憑據的儀表盤創建一個模板,點擊該按鈕
- Ajax調用PHP的那驗證憑證並返回用戶是否正確輸入了它們以及用戶的類型。
- Ajax獲取響應並用參數
user_type
調用一個新函數。根據用戶類型,正確的內容將被渲染。
現在,我的代碼如下所示:
//app/views/start.php
<form class="navbar-form pull-right" method="post" action="#/login">
<input class="span2" type="text" placeholder="Email">
<input class="span2" type="password" placeholder="Password">
<button type="submit" class="btn">Sign in</button>
</form>
//public/js/myjs.js(呈現新的內容)
mtp = (function() {
var app = null;
var init = function($) {
app = $.sammy('#pagecontainer',function() {
this.use('Template');
this.get('#/', function(){});
this.post('#/submitrequestfrontpage', function(){
context=this;
$("#pagecontainer").html('');
context.render('addlifecircledata.template').appendTo($("#pagecontainer"));
});
this.post('#/login',function(){
//need to put intelligent stuff here
});
});
$(function() {
app.run('#/');
});
};
return {
init: init
}
})();
雖然邏輯似乎沒問題,但我不知道該如何開始編寫代碼。具體來說,如何獲取myjs.js中的參數以啓動AJAX調用,然後獲取響應。