1
檢索在飛鏢聚合物中的登錄表單中輸入的用戶名的最佳方式是在下一頁將其重定向到的頁面中讀取?將登錄表單中的值傳遞到儀表板
登錄組分是如下 -
@CustomTag('alfresco-login-form')
class LoginFormComponent extends FormElement with Polymer, Observable {
LoginFormComponent.created() : super.created();
@observable String username = "";
@observable String password = "";
@observable Map loginData = toObservable({
'username' : '',
'password' : ''
});
@observable String serverResponse = '';
HttpRequest request;
void submitForm(Event e, var detail, Node target) {
e.preventDefault(); // Don't do the default submit.
request = new HttpRequest();
request.onReadyStateChange.listen(onData);
// POST the data to the server.
var url = 'http://127.0.0.1/alfresco/service/api/login';
request.open("POST", url);
request.send(_loginDataAsJsonData());
}
void onData(_) {
if (request.readyState == HttpRequest.DONE &&
request.status == 200) {
// Data saved OK.
serverResponse = 'Server Sez: ' + request.responseText;
Map parsedMap = JSON.decode(request.responseText);
var currentTicket = new Ticket(parsedMap["data"]["ticket"]);
//keeps the back history button active
//window.location.assign('dashboard.html');
//doesn't keep the back history button active
//doesn't put the originating page in the session history
window.location.replace('dashboard.html');
} else if (request.readyState == HttpRequest.DONE &&
request.status == 0) {
// Status is 0...most likely the server isn't running.
serverResponse = 'No server';
}
}
String _loginDataAsJsonData(){
return JSON.encode(loginData);
}
}
我需要訪問該loginData [ '用戶名'] & parsedMap [ 「數據」] [ 「票」],在可用頁面dashboard.html。
我想你應該多解釋一下你想做的事情。你爲什麼重定向。重定向之前執行的是什麼。根據您提供的信息,我建議在表單提交時將數據發送到服務器。用會話標識(例如cookie)識別用戶,並從新頁面上的服務器獲取數據。 –
@GünterZöchbauer我已根據您的要求編輯了該問題。讓我知道你是否需要我的更多信息。 –