0

私は自分が間違っていることを見つけることができません.3日以上この問題をグーグルで調べてきました.

AjaxTest.php (HTML および JavaScript ページ)

<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
</head>
<script>
$(document).ready(function() {
    $("#rchar").submit(function(event){
        alert("hahahaha");
        var request;
        // abort any pending request
        if (request) {
            request.abort();
        }
        // setup some local variables
        var $form = $(this);
        // let's select and cache all the fields
        var $inputs = $form.find("input, select, button, textarea");
        // serialize the data in the form
        var serializedData = $form.serialize();

        // fire off the request to /form.php
        request = $.ajax({
        url: 'postregister.php',
        type: "POST",
        data: serializedData,
        success: function(result){
            console.log(result);
        },
        error: function(){
            console.log('error');
        }   
    });

        // callback handler that will be called on success
        request.done(function (response, textStatus, jqXHR){
        $("#navigation").html(serializedData);
        });

        // callback handler that will be called on failure
        request.fail(function (jqXHR, textStatus, errorThrown){
            // log the error to the console
            console.error(
                "The following error occured: "+
                textStatus, errorThrown
            );
        });

        // prevent default posting of form
        event.preventDefault();
    });
});
</script>
 <body>
    <form id="rchar" method="POST" action="postregister.php">
    <h3>Test Form!</h3>
    <table id="leftalignment1">
    <tbody>
    <tr><td>Name: </td><td><input type="text" size="35px" id="name" value="" placeholder="Name" name="name"><input type="hidden" value="Test" id="hidden" name="hidden"></td></tr>
    <tr><td>Password:</td><td><input type="password" size="35px" placeholder="Password" id="password" name="password"></td><td></td></tr>
    </tbody>
    </table><br><br>
    <input action="submit" value="  Register  " id="submit" type="submit"><br>
    </form>
</body>
</html>

postregister.php (変数を投稿・表示するページ)

<?php
echo $_POST;
var_dump($oldname);
  $oldname = $_POST['hidden'];
  $password = $_POST['password'];
$title = "Your password is: " . $password;
  echo $title . "<br>" . $password . "<br>Your old name was: <br>" . $oldname;
?>

JavaScript コンソールに表示される結果は次のとおりです。

ArrayNULL
Your password is: <br><br>Your old name was: <br> 

このコードは編集されていないことに注意してください。これは、コードが現在の形式で実際にどのように見えるかです。

どんな助けでも大歓迎です:)

4

0 に答える 0