我有引用应用程序列出引号我有一个工作正常的登录页面,但我想在他们登录时显示用户名 这是我的登录方法
function logIn() {
var URL = 'http://localhost:8080/RESTful/rest/crazyquotes/login';
console.log('logInUser');
$.ajax({
type: 'POST',
async: true,
contentType: 'application/json',
url: URL,
dataType: 'json',
data: formToJSONLogin(),
success: function(data, textStatus, jqXHR){
window.location.replace('http://localhost:8080/RESTful/quotes.html');
window.alert(showuser());
},
error: function(jqXHR, textStatus, errorThrown){
window.alert('User does not exit');
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
}
});
}
获取用户名的方法
function getusername() {
var user = JSON.stringify({
'username': $('#loginuser').val()
});
var obj = JSON.parse(user);
return obj.username;
}
我想在这里显示用户名
<div class="bs-Signout">
<div class="btn-group">
<button type="button" id="currentlogged" data-toggle="dropdown" class="btn btn-primary dropdown-toggle">I want to display the username here<span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="http://localhost:8080/RESTful/index.html">Sign out</a></li>
</ul>
</div>
</div>
编辑:我有方法,但如何在成功后调用它,以便显示在quotes.html中?
function logIn() {
var URL = 'http://localhost:8080/RESTful/rest/crazyquotes/login';
console.log('logInUser');
$.ajax({
type: 'POST',
async: true,
contentType: 'application/json',
url: URL,
dataType: 'json',
data: formToJSONLogin(),
success: function(data, textStatus, jqXHR){
window.location.replace('http://localhost:8080/RESTful/quotes.html');
getusername();
},
error: function(jqXHR, textStatus, errorThrown){
window.alert('User does not exit');
console.log(jqXHR);
console.log(textStatus);
console.log(errorThrown);
}
});
}
答案 0 :(得分:-1)
我只想在之前添加用户名:
$('username').before('.caret');