Jquery终端注册&登录
Jquery Terminal register & login
我有问题,我想要用户注册然后登录,但是这是错误任何人都可以帮助我吗?我看到了文档。这是文档 jquery termi[jquery terminal]1nal
的 link
这是我的脚本:
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);
}
}
}
谢谢
你有无效的 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');
}
我有问题,我想要用户注册然后登录,但是这是错误任何人都可以帮助我吗?我看到了文档。这是文档 jquery termi[jquery terminal]1nal
的 link这是我的脚本:
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);
}
}
}
谢谢
你有无效的 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');
}