-2

我有一个加载的页面,然后当加载完成时,它使用 Jquery 将内容加载到一个框中。该框包含一个表格。我希望它也能够通过 jQuery 提交表单。但是,当我尝试它时,页面只是刷新,我在 URL 栏中获得了 GET 变量。

jQuery,确实加载并假设提交表单:

$(document).ready(function(){
$("#passchangebox").load("boxes/settings_security_password.php?uID=" + uID, function() {
    $(".form_error").hide();
    $("#changepasswordloader").hide();
});
$("#passwordchange").submit(function(event) {  
    $('.form_error').hide();  
    var pass = $("input#pass").val();  
    if (pass === "") {  
        $("#pass_error").show();  
        $("input#pass").focus();  
        return false;
    }
    cpass = $("input#cpass").val();  
    if (cpass === "") {  
        $("#cpass_error").show();  
        $("input#cpass").focus(); 
        return false;
    }
    if(pass !== cpass){
        $("#match_error").show();  
        $("input#cpass").focus(); 
        return false;
    }
    email = $("input#email").val();
    $.ajax({
        type: "POST",
        url: "functions/settings_passwordchange.php",
        data: $('#passwordchange').serialize(),
        success: function(result) {
            if(result == 1){       
                $('input#pass').val("");
                $('input#cpass').val("");
                $('#payment_window_message_success').fadeIn(300);
                $('#payment_window_message_success').delay(3000).fadeOut(700);
                return false;
            }
        },
        error: function() {
            $('#payment_window_message_error_mes').html("An error occured, form was not submitted");
            $('#payment_window_message_error').fadeIn(300);
            $('#payment_window_message_error').delay(3000).fadeOut(700);
        }
    });
    event.preventDefault();
    return false;
    });
});

加载到页面中的 PHP 包含以下表单:

<?php
//get required config file and check login
if(!@include("../connect.php")){
    echo"<aside>
        <div class='error' id='errorconnecthide-this'>
            <img src='http://resources.domain.co.nz/backgrounds/icon_error.png' class='messageimg' />
            <h4>Error - Current Page</h4>
            <p>There was an error making a connection to the database. Please try again later.</p>
        </div>
    </aside>";
} elseif(isset($_GET['uID'])){
    $uID = strip_tags(stripslashes($_GET['uID']));
    if(!is_numeric($uID)){
        echo"<aside>
            <div class='error' id='errorconnecthide-this'>
                <img src='http://resources.domain.co.nz/backgrounds/icon_error.png' class='messageimg' />
                <h4>Error - User</h4>
                <p>There was an error retrieving the user information. Please try again later.</p>
            </div>
        </aside>";
    } else {
        //GET THE USERS EMAIL
        $get_custInfo = 'singleuser';
        $userInfo_ID = $uID;
        if(!include("../classes/global_userinfo_details.php")){
            echo"<aside>
                <div class='error' id='errorconnecthide-this'>
                    <img src='http://resources.domain.co.nz/backgrounds/icon_error.png' class='messageimg' />
                    <h4>Error - User</h4>
                    <p>There was an error retrieving the user information. Please try again later.</p>
                </div>
            </aside>";
        } else {
            $details = mysqli_fetch_assoc($userInfo_qry);
            $email = stripslashes($details['userinfo_email']);
            echo"<form class=\"halfboxform\" id=\"passwordchange\">
                <fieldset>
                    <br />
                    <input type=\"hidden\" id=\"email\" value=\"$email\" />
                    <label for=\"pass\">New Password:</label>
                    <input type=\"password\" name=\"pass\" id=\"pass\" size=\"45\" />
                    <p class=\"form_error clearb red input\" id=\"pass_error\">This field is required.</p>
                    <label for=\"cpass\" class=\"clearb\">Confirm:</label>
                    <input type=\"password\" name=\"cpass\" id=\"cpass\" size=\"45\" />
                    <p class=\"form_error clearb red input\" id=\"cpass_error\">This field is required.</p>
                    <p class=\"form_error clearb red input\" id=\"match_error\">Those passwords didnt match.</p>
                    <br class=\"clearl\" />
                    <br />
                    <input type=\"submit\" value=\"Update Login Details\" class=\"submit\" />
                </fieldset>
                <div class='clear'></div>
            </form>";
        }
    }
} else {
    echo"<aside>
        <div class='error' id='errordisplayhide-this'>
            <img src='http://resources.domain.co.nz/backgrounds/icon_error.png' class='messageimg' />
            <h4>Error - Unknown</h4>
            <p>There was an error retrieving the necessary information. Please try again later.</p>
        </div>
    </aside>";
}
?>

对此的任何帮助都非常感谢:D

4

1 回答 1

0

解决方案是将提交功能移动到加载成功功能中,如下所示:

$(document).ready(function(){
    $("#passchangebox").load("boxes/settings_security_password.php?uID=" + uID, function() {
        $(".form_error").hide();
        $("#changepasswordloader").hide();
        $("#passwordchange").submit(function(event) {  

有信心我以前尝试过这个但它没有用,是否是我不确定的评论建议所做的更改的组合。也许有人可以解释为什么?感谢所有评论并帮助改进的人。

于 2013-04-10T23:35:31.837 回答