我有一个问题,我想要用户注册然后登录,但这里是错误的,任何人可以帮助我?我看过文档了。以下是jquery termi[jquery terminal]1nal文档的链接
下面是我的脚本:
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);
}
}
} 谢谢
发布于 2018-08-26 02:21:45
你有无效的JavaScript你有标签和函数声明,它们应该放在一个对象中,如下所示:
var x = {
login: function() {
}
};它应该是第二个参数中对象的一部分,它是options对象。
.terminal(function(command) {
if (command === 'register') {
}
}, {
login: function(...) {
...
}
});对于您在使用login命令时遇到的确切问题,需要像这样调用login方法:
} 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');
}https://stackoverflow.com/questions/52019594
复制相似问题