简体   繁体   中英

jQuery in Phonegap Login Form

I'm making a login form for my Phonegap app, and am unable to send the user input to my server for validation.

Right now, I'm just trying to make sure the user input is being referenced in the first place, so I'm trying to alert it out.

When I do that, nothing happens.

But, if I comment out the hashing, everything works fine.

Here's a link to the hashing script. It's worked before in other examples.

Maybe I'm rusty with jQuery and missing something stupid, I don't know.

JQUERY

$(document).ready(function()
{
    $("#login").submit(function()
    {
        -- This block is what is commented or not to make the alert work --
        var NoHashPwd = $("#password").val();
        var HashedPwd = hex_sha512(NoHashPwd.value);
        $("#p").val(HashedPwd);
        password.value = "";
        -- End block --

        var uname = $("#uname").val();
        var p = $("#p").val();

        alert(uname);
    });
});

LOGIN FORM

<form id="login">
    <input type="hidden" name="login_lat" id="login_lat" value="fill" />
    <input type="hidden" name="login_lon" id="login_lon" value="fill" />
    <input type="hidden" name="p" id="p" value="coming" />

    <label for="uname">Username: </label>
    <input type="text" name="uname" id="uname" />
    <br />
    <label for="password">Password: </label>
    <input type="password" name="password" id="password" />
    <br />
    <input type="submit" value="Login" name="login" />
</form>

So I fixed it with the help of @apanosa

He was right about nothing being triggered and the NoHashPwd.value being incorrect.

By incorrect, I mean it was NULL and there was no value attached.

I changed my code to just make NoHashPwd a variable and referenced that in the hash_sha512 function.

Thanks for the help @apanosa

New JS

var NoHashPwd = $("#password").val();
var HashedPwd = hex_sha512(NoHashPwd);
$("#p").val(HashedPwd);
$("#password").val(" ");

var uname = $("#uname").val();
var login_lat = $("#login_lat").val();
var login_lon = $("#login_lon").val();
var p = $("#p").val();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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