我找不到我做错了什么,我已经在谷歌上搜索这个问题超过 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>
请注意,此代码没有被编辑,这是代码在当前形式中的实际外观。
任何帮助,将不胜感激 :)