数据库从javascript中捕获错误的结果

时间:2016-12-28 22:34:49

标签: javascript

是的,有人可以帮我吗?所以我正在创建一个Web应用程序,用户可以通过单击1-40中的数字来破解Vault代码。它们只允许点击6组数字,例如“6”,“20”,“1”,“40”,“27”,“15”。所以我的数据库中有一个数据变量“guess”,int(12)作为下面这个JS中的var数字。问题是每当我尝试“40”,“39”,“38”,“37”,“36”,“35”时。数据库将捕获“2147483647”,我很困惑,为什么,我正在做的事情肯定有问题。我不是很专业的JS,我只是按照一些指南。当我在保险库中有0-9个数字并且在数据库中的数据var“guess”中有int(6)时,这是有效的。请帮忙,谢谢!

var numbers     = document.querySelectorAll('.number');
var screenSpans = document.querySelectorAll('#screen span');
var clear       = document.getElementById('clear');
var enter       = document.getElementById('enter');
var errorModal  = document.getElementById('digitAmountAlert');
var currEmail   = document.getElementById('currEmail').innerHTML.replace(/\s/g, '');
var lastModal   = document.getElementById('lastModal');
var main        = document.getElementById('main');
var guess       = '';
var reset;

clear.addEventListener('click', function(){
reset = 0;
for (var i = screenSpans.length - 1; i >= 0; i--) {
    if (screenSpans[i].innerHTML != '' && reset == 0){
        screenSpans[i].innerHTML = '';
        reset = 1;
    }
};
});

enter.addEventListener('click', function(){
reset = 0;
for (var i = 0; i < screenSpans.length; i++) {

    // Catch if they have not entered enough digits
    if (screenSpans[i].innerHTML == ''){
        errorModal.className = 'modal';
        setTimeout(function(){
            errorModal.className = 'modal hide';
        }, 4000);

    } else {
        guess = guess+screenSpans[i].innerHTML;
        if (guess.length == 12){
            $.ajax({
                  url: "submit.php",
                  method: "POST",
                  data: { guess: guess, email: currEmail }
            });

            lastModal.className = 'modal';
            main.className = 'hide';
        }
    }
};
guess = '';
});

for (var i = numbers.length - 1; i >= 0; i--) {
numbers[i].addEventListener('click', function(){
    reset = 0;
    nextSpan(this.innerHTML);
});
};

function nextSpan (currNumber){
for (var i = 0; i < screenSpans.length; i++) {
    if (screenSpans[i].innerHTML == '' && reset == 0){
        screenSpans[i].innerHTML = currNumber;
        reset = 1;
    }
};
}

/*
|---------------------------------------------------
| FORM SUBMIT CHECK
|---------------------------------------------------
*/

var submitButton = document.getElementById('startButton');
var form = document.getElementById('form');
var goAhead = true;

submitButton.addEventListener('click', function(){
var i, j, q = [];
for (var i = 0; i < form.elements.length; i++) {
    if (form.elements[i].nodeName == "INPUT"){
        q.push(form.elements[i].name + "=" +     encodeURIComponent(form.elements[i].value));
        var inputValue = encodeURIComponent(form.elements[i].value)
        if ((inputValue == '' || inputValue == null) && (form.elements[i].name != 'online')){
            // NOT COMPLETE
            goAhead = false;
            console.log(form.elements[i].name)
        }
    }
}

if (goAhead){
    // SUBMIT
    document.getElementById('form').submit();
} else {
    this.innerHTML = "Please fill out all the fields & try again";
    setTimeout(function(){
        submitButton.innerHTML = "Let's Play!";
    }, 7000);
    goAhead = true;
}
});

0 个答案:

没有答案