使用ajax刷新修改密码,AJAX密码更改

,所以我想实现密码更改功能,我的网站,我想提交密码表单不刷新页面。所以我试图使用ajax。这里是我的html:

AJAX密码更改

Current Password

New Password

Verify Password

然后jQuery的:

$('#change_Pass').submit(function(e){

$.ajax({

data: $(this).serialize(), // get the form data

type: $(this).attr('POST'), // GET or POST

url: $(this).attr('Private/change_password.php'), // the file to call

success: function(response) { // on success..

$('#success_div).html(response); // update the DIV

},

error: function(e, x, r) { // on error..

$('#error_div).html(e); // update the DIV

}

});

e.preventDefault();

});

然后是PHP:

$usr = $_SESSION["username"];

$old_pwd = $_POST["change_password"];

$new_pwd = $_POST["new_password"];

$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();

}

但是我卡上的几件事情。

1)如何张贴到change_password.php,而不是对其进行序列化,这样我可以使用$_POST数据?

2)change_password看起来是否正确?它基本上检查用户输入的数据库中现有的密码为current password。如果它们匹配,则它会更改密码。

2012-10-20

Richard

+0

也使$( '#success_div')HTML(响应)。 //更新DIV正确 –

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值