Jquery表单值确认

时间:2016-04-14 14:22:35

标签: javascript php jquery cordova validation

有人能告诉我为什么这会出现错误吗?我正在尝试使用类似的代码在我使用jquery mobile构建的Cordova应用程序中的用户身份验证系统,以确保密码和密码确认是相同的。然后将这些数据发送到我服务器上的php文件,然后根据验证,然后php将返回" success"或"失败"。因此,我有另一个问题是如何根据从php文件返回的结果我可以改变我对应用程序的看法?如果有人可以建议我这样做的好方法或者我可以学习的教程,那将是很棒的,因为我无法找到这方面的好教程,因为我是这一切的新手。

$(document).on('pagebeforeshow', '#signuppage', function () {
$(document).on('click', '#signupbutton', function () {
    if ($('#confirmpassword').val() === $('#password').val()) {
        $.ajax({
            url: 'http://localhost/appAuth/profiling.php',
            data: {
                action: 'signup',
                formData: $('#signupform').serialize()
            },
            type:'post',
            async: true,
            dataType: 'json',
            beforeSend: function () {
                //this is the callback function will trigger before data is sent
                $.mobile.showPageLoadingMsg(true);
            },
            complete: function () {
                //this is the callback functino will trigger on data sent/received complete
                $.mobile.hidePageLoadingMsg();
            },
            success: function (result) {
                resultObject.formSubmitionResult = result;
                $mobile.changePage("#collections");
            },
            error: function (request, error) {
                //this is the callback function will trigger on unsuccessful action
                alert('Network error has occured please try again!');
            }
        });
    }
    else
    {
        alert('Please make sure the two passwords match!');
    }
    return false; //cancel original event to prevent form submitting
});
});

以下是请求的HTML:

    <div data-role="page" id="signuppage" style="background-color:#454545;">
    <div data-role="header" id="head">
        <h1>
            <a href="#" class="ui-btn ui-btn-left ui-corner-all ui-shadow ui-btn-inline ui-icon-back ui-btn-icon-left" data-rel="back">Back</a>
            <strong>Signup</strong>
        </h1>
    </div>
    <div data-role="main" class="ui-content">
        <form id="signupform" data-ajax="false">
                <fieldset data-role="fieldcontain">
                    <label for="firstname">First name:</label>
                    <input type="text" name="firstname" id="firstname" placeholder="Enter First Name" required>
                </fieldset>
                <fieldset data-role="fieldcontain">
                    <label for="lastname">Last name:</label>
                    <input type="text" name="lastname" id="lastname" placeholder="Enter Last Name" required>
                </fieldset>
                <fieldset data-role="fieldcontain">
                    <label for="email">Email:</label>
                    <input type="email" name="email" id="email" placeholder="Your Email..." required email>
                </fieldset>
                <fieldset data-role="fieldcontain">
                    <label for="username">Username:</label>
                    <input type="text" name="username" id="username" placeholder="Enter Username" required>
                </fieldset>
                <fieldset data-role="fieldcontain">
                    <label for="password">Password:</label>
                    <input type="password" name="password" id="password" placeholder="Enter Password" required>
                </fieldset>
                <fieldset data-role="fieldcontain">
                    <label for="confirmpassword">Confirm password:</label>
                    <input type="password" name="confirmpassword" id="confirmpassword" placeholder="Confirm password" required equalTo="password">
                </fieldset>
            <input type="submit" data-inline="true" value="Submit" name="signupbutton" id="signupbutton">
        </form>
    </div>
</div>

0 个答案:

没有答案