简体   繁体   English

使用Json登录

[英]Login using Json

I am trying to develop a login process using json. 我正在尝试使用json开发登录过程。 My problem is that when I make many login attempts , parameters are not overriden but concatenated. 我的问题是,当我进行多次登录尝试时,参数不会被覆盖而是被串联。 Below is the code I'm writing. 下面是我正在编写的代码。 I do not see where the problem is. 我看不出问题出在哪里。 Thank you in advance . 先感谢您 。

var loginReq = Titanium.Network.createHTTPClient();

    loginReq.onload = function() {


var json = this.responseText;
Titanium.API.info("step 1 done");
var response = JSON.parse(json);

if (response.status == true) {


    Titanium.App.Properties.setString("key", response.key);
    alert("Success");

} else {
    alert("Email or password wrong");
}
};



 function doConnVerif() {

if ($.email.value != '' && $.password.value != '') {

    loginReq.open("POST", "URL");

    loginReq.send({
        'email' : $.email.value ,
        'password' : $.password.value

    });



} else {
    alert("Enter email and password");

}
  }

By your question I can't grasp the full aspect of the problem, but definitely a good idea would be only allow one login attempt at a time. 根据您的问题,我无法理解问题的全部内容,但是,绝对可以将一次登录尝试设为一个好主意。

Something like: 就像是:

var pendingRequest = false;

// ...

if(!pendingRequest) {
    loginReq.send({
        'email' : $.email.value ,
        'password' : $.password.value
    });
    pendingRequest = true
}

// ...
loginReq.onload = function() {
    pendingRequest = false
// ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM