除非重新加载页面,否则AJAX表单不提交

时间:2017-12-06 20:59:00

标签: jquery ajax forms form-submit

美好的一天......我需要帮助一个页面,其中包含一个使用jquery提交的表单...表单工作正常但是只有在刷新浏览器时它才有效。当通过链接打开页面时,表单提交根本不响应,直到您刷新浏览器!事实上,页面上没有任何脚本响应,包括验证脚本......直到刷新浏览器...我需要帮助解决这个问题

register.html看起来像这样

if difference.second! <= 0 {

这个页面工作正常,表单验证和提交都工作正常,但是如果这个页面是通过链接打开的,那么脚本似乎都没有响应。当你单击#btc-register页面时只需重新加载,没有其他任何事情发生... 任何建议将不胜感激

下面是register.js

<!DOCTYPE html><html><head></head>
<body>
<div data-role="page" id="register" data-theme="b">

    <div role="main" class="ui-content">
    
            <div class="content-block-login">
                            <div class="form_logo">Create an Account</div>
                            <div id="error_message"></div>
                            <div class="loginform">
                                <form class="register-form" id="RegisterForm">
                                
                                <input type="text" name="Username" id="reg-username" class="form_input required" placeholder="username" data-role="none" />
                                
                                <input type="text" name="Email" id="reg-email" value="" class="form_input required" placeholder="email" data-role="none" />
                                <input type="password" name="Password" id="reg-password" value="" class="form_input required" placeholder="password" data-role="none" />
                                <input type="password" name="Password" id="reg-repeat-password" value="" class="form_input required" placeholder="confirm password" data-role="none" />
                                <input type="hidden" name="device_fingerprint" id="dfp" value="" />
                                <button type="submit" id="btn-register" class="form_submit" >Register</button>
                                </form>
                             
                            </div>
       
            </div>

    </div>


</div>

<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/register.js"></script>

<script>
$( "#RegisterForm" ).submit(function( event ) {
   event.preventDefault();
});
</script>
</body>
</html>

}); var register = {};

register.registerUser = function(data){

enter  $(document).ready(function () {
//button register click
$("#btn-register").click(function () {

  //  alert("yes me");
    if(register.validateRegistration() === true) {
        //validation passed
        var regMail     = $("#reg-email").val(),
            regUser     = $("#reg-username").val(),
            regPass     = $("#reg-password").val(),
            regPassConf = $("#reg-repeat-password").val(),
            devFinger   = $("#dfp").val();

        var data = { 
            userData: {
                email           : regMail,
                username        : regUser,
                password        : regPass,
                confirm_password: regPassConf,
                dfp             : devFinger

            },
            fieldId: {
                email           : "reg-email",
                username        : "reg-username",
                password        : "reg-password",
                confirm_password: "reg-repeat-password",
                dfp             : "dfp"

            }
        };

        //send data to server
        register.registerUser(data);

    }                        
});

};

register.validateRegistration = function(){     var valid = true;

var btn = $("#btn-register");
asengine.loadingButton(btn, "Validating...");

$.ajax({
    url: "http://mywebsite/api/Ajax.php",
    type: "POST",
    data: {
        action  : "registerUser",
        user    : data
    },
    success: function (result) {

        asengine.removeLoadingButton(btn);

        console.log(result);

        var rstatus = result.status;
        var rmsg = result.msg;

        if(rstatus === "error") {
            //error
            var rerrors = result.errors[0].msg;
            jQuery("#btn-register").html("Registration Failed!!");

        }
        else {
            //display success message
            $("#error_message").addClass("successflash");
            $("#error_message").html("<p>" + rmsg + "</p>");
            setTimeout($("#btn-register").html("Success!"),7000);

        }
    }
});

};  这里

0 个答案:

没有答案