我有问题,我希望用户注册然后登录,但是在这里出现错误,有人可以帮助我吗?我看了文件。这是jquery termi[jquery terminal] 1 nal
文档的链接这是我的脚本:
if (command == 'register') {
term.push(function(command, term) {
term.pause();
$.ajax({
url: "register.php",
type: "post",
data: {data_register : command },
success: function (msg) {
term.echo(yellow('Data Saved Successfully !'));
term.resume();
},
error: function(jqXHR, textStatus, errorThrown) {
term.resume();
}
});
},
{
prompt: " > "
});
} else if (command == 'login'){
login: function(user, password, callback) {
if (user == 'demo' && password == 'secret') {
callback('SECRET TOKEN');
} else {
callback(null);
}
}
}
此行的错误:
else if (command == 'login'){
login: function(user, password, callback) {
if (user == 'demo' && password == 'secret') {
callback('SECRET TOKEN');
} else {
callback(null);
}
}
}
谢谢
答案 0 :(得分:0)
您的JavaScript无效,您具有标签和函数声明,应将其放在这样的对象中:
var x = {
login: function() {
}
};
应该是第二个参数(对象是选项对象)中对象的一部分。
.terminal(function(command) {
if (command === 'register') {
}
}, {
login: function(...) {
...
}
});
对于您使用登录命令时遇到的确切问题,您需要以这种方式调用登录方法:
} else if (command == 'login'){
term.login(function(user, password, callback) {
// to get the token you should send user and password to the server
if (user == 'demo' && password == 'secret') {
callback('SECRET TOKEN');
} else {
callback(null);
}
});
} else if (term.token()) {
// here are commands that will only work after user login
// but you need to know that user may add token in developer tools
// so you should use additional check if token is valid by sending token
// to the server, or if you're invoking command on the server then just
// send the token and validate it there
} else {
term.error('invalid command');
}