我需要从使用 GET 从服务器的用户列表中发布用户名,但如何将该用户名作为字符串发布。任何帮助表示赞赏,在此先感谢!
//get a list of users from server side
$.getJSON(
'/userlist',
function(data) {
var user = data.users;
$("#utbildning").text(user[1].username);
$("#tekniker").text(user[2].username);
}
);
//post user name and password at login
$(document).ready(function() {
$("#knapp").click(function(){
//name of the user should be a name from the user list comes from server
var name=$.getJSON(
'/userlist',
function(data) {
var user = data.users;
user[1].username;
}
);
var pass=$("#kod").val(); //password from input field
var data = new Object();
data["username"] = name;
data["password"] = pass;
$.ajax(
{
url: "/login",
data: JSON.stringify(data),
processData: false,
type: 'POST',
contentType: 'application/json',
}
);
});
})