因此,我正在尝试实现基于 ajax 的密码更改,以便在用户点击提交时页面不会刷新。所以这是我的 html、jquery 和 php:
Current Password<input type="password" id="change_password" name="change_password"><br>
New Password<input type="password" id="new_password" name="new_password"><br>
Verify Password<input type="password" id="verify_password" name="verify_password"><br>
查询:
$('#change_Pass').submit(function(e){
var $this = $(this);
$.ajax({
data: $(this).serialize(), // get the form data
type: $(this).attr('method'), // GET or POST
url: '/Private/change_password.php', // the file to call
success: function(response) { // on success..
//$('#success_div).html(response); // update the DIV
alert("good");
},
error: function(e, x, r) { // on error..
//$('#error_div).html(e); // update the DIV
alert("bad");
}
});
e.preventDefault();
return false; //so it doesn't refresh or submit the page
});
PHP:
<?php
session_start();
require_once '../classes/Bcrypt.php';
ini_set('display_errors', 'On');
error_reporting(E_ALL | E_STRICT);
$usr = $_SESSION["username"];
$old_pwd = $_POST["change_password"];
$new_pwd = $_POST["new_password"];
$new_pwd = Bcrypt::hash($new_pwd);
try {
$link = new PDO('mysql:host=*;dbname=*;charset=UTF-8','*','*');
$query = "SELECT *
FROM Conference
WHERE Username = :un";
$stmt = $link->prepare($query);
$stmt->bindParam(':un', $usr);
$stmt->execute();
$row = $stmt->fetchAll();
$hash = $row[0]["Password"];
$is_correct = Bcrypt::check($old_pwd, $hash);
if($is_correct) {
$query = "UPDATE Conference
SET `Password`=:new_pwd
WHERE Username = :usr";
$stmt = $link->prepare($query);
$stmt->bindParam(':new_pwd', $new_pwd);
$stmt->bindParam(':usr', $usr);
$stmt->execute();
}
} catch(PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
我的文件结构只是:
Folder
|--Front.php
|--Private
|--change_password.php
但是每次我输入这些东西并点击提交。它试图去www.domain.com/Folder/change_password.php
而不是www.domain.com/Folder/Private/change_password.php
。它只是说
The requested URL /Folder/change_password.php was not found on this server.
我尝试了完整的网址,/Private/change_password.php
但没有任何效果。我不明白为什么它看不到文件夹。有任何想法吗?