そのため、ユーザーが送信を押したときにページが更新されないように、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>
Jクエリ:
$('#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.
完全な URL を試してみましたが/Private/change_password.php
、何も機能しません。フォルダが表示されない理由がわかりません。何か案は?