首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jquery终端注册和登录

Jquery终端注册和登录
EN

Stack Overflow用户
提问于 2018-08-26 01:21:53
回答 1查看 245关注 0票数 0

我有一个问题,我想要用户注册然后登录,但这里是错误的,任何人可以帮助我?我看过文档了。以下是jquery termi[jquery terminal]1nal文档的链接

下面是我的脚本:

代码语言:javascript
复制
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);
        }
      }
    } 

这一行的错误:

代码语言:javascript
复制
else if (command == 'login'){
          login: function(user, password, callback) {
            if (user == 'demo' && password == 'secret') {
                callback('SECRET TOKEN');
            } else {
                callback(null);
            }
          }
        } 

谢谢

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-26 02:21:45

你有无效的JavaScript你有标签和函数声明,它们应该放在一个对象中,如下所示:

代码语言:javascript
复制
var x = {
   login: function() {
   }
};

它应该是第二个参数中对象的一部分,它是options对象。

代码语言:javascript
复制
.terminal(function(command) {

   if (command === 'register') {
   }
}, {
   login: function(...) {
      ...
   }
});

对于您在使用login命令时遇到的确切问题,需要像这样调用login方法:

代码语言:javascript
复制
} 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');
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52019594

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档