为什么post 提交后,还没执行 Ajax 就报500错,什么原因呢?
*reset_pwd.js*
;
var user_resetPwd_opt = {
init: function(){
this.bindEvent();
},
bindEvent: function(){
var that = this;
$("#save").click(function(){
var btn_target = $(this);
if( btn_target.hasClass("disabled") ){
alert("正在处理,请不要频繁点击~~");
return;
}
var old_password = $("#old_password").val();
if(!old_password){
alert("请输入原密码~~",$("#old_password"));
return false;
}
var new_password = $("#new_password").val();
if(!new_password || new_password.length<6){
alert("请输入不少于6位的新密码!",$("#new_password") );
return false;
}
btn_target.addClass("disabled");
var data = {
'old_password':$("#old_password").val(),
'new_password':$("#new_password").val()
};
//执行到这里,就不往下执行了,ajax方法中都不进去,然后报 500 错
$.ajax({
url:'/web/user/reset-pwd',
type:'POST',
data:data,
dataType:'json',
success:function(res){
console.log(res);
btn_target.removeClass("disabled");
var callback = null;
if( res.code == 200 ){
callback = function(){
window.location.href = window.location.href;
}
}
common_ops.alert( res.msg,callback );
}
});
});
}
};
$(function(){
user_resetPwd_opt.init();
});
*php 接口文件*
//修改密码,这个接口方法也不执行!!!根本进不来
public function actionResetPwd(){
if( \Yii::$app->request->isGet){
return $this->render("reset_pwd",[
'info' => $this->current_user
]);
}
$old_password = trim($this->post('old_password',''));
$new_password = trim($this->post('new_password',''));
var_dump($old_password);
if(!$old_password){
return $this->renderJSON([],"请输入原密码!",-1);
}
if( mb_strlen($new_password,"utf-8") < 6 ){
return $this->renderJSON([],"请输入不少于6位的新密码!",-1);
}
if($old_password == $new_password){
return $this->renderJSON([],"请重新输入一个吧,新密码和原密码不能相同哦!",-1);
}
$current_user = $this->current_user;
if (!$current_user->verifyPassword($old_password)) {
return $this->renderJSON([],"请检查原密码是否正确~~",-1);
}
if( $current_user['uid'] == 2 ){
return $this->renderJSON([],"该账号为测试账号,请不要修改密码~~",-1);
}
$current_user->setPassword($new_password);
$current_user->updated_time = date("Y-m-d H:i:s");
$current_user->update(0);
$this->setLoginStatus( $current_user );
return $this->renderJSON([],"修改成功~~");
}
以下为返回的 500 提示信息,网上找了好久了,都没有找到对应的解决办法:
Request URL: http://localhost/web/user/reset-pwd
Request Method: POST
Status Code: 500 Internal Server Error
Remote Address: [::1]:80
Referrer Policy: no-referrer-when-downgrade
Connection: close
Content-Length: 1086
Content-Type: text/html; charset=UTF-8
Date: Wed, 07 Aug 2019 14:34:05 GMT
Server: Apache/2.4.39 (Win64) PHP/7.2.18
X-Debug-Duration: 52
X-Debug-Link: /debug/default/view?tag=5d4ae15d5a12f
X-Debug-Tag: 5d4ae15d5a12f
X-Powered-By: PHP/7.2.18
Accept: application/json, text/javascript, */*; q=0.01
Accept-Encoding: gzip, deflate, br
Accept-Language: zh-CN,zh;q=0.9
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 43
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Cookie: _csrf=c0529d0c9fadbedf960423cd3d1160852fa4528d1ca9477ae5b7ecc462d6dd47a%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22_csrf%22%3Bi%3A1%3Bs%3A32%3A%22zOrm1uMkflCmSJt-e64VkAsVzHNAqA7U%22%3B%7D; SL_G_WPT_TO=zh-CN; SL_GWPT_Show_Hide_tmp=undefined; SL_wptGlobTipTmp=undefined; mooc_book=117caee042eb7b1cb219735ee3732fe9aa7ebf78321d05c7a78b8a62739d9e24a%3A2%3A%7Bi%3A0%3Bs%3A9%3A%22mooc_book%22%3Bi%3A1%3Bs%3A34%3A%22143af06bfcb66cc61e2f0aa96abfe0f5%231%22%3B%7D
Host: localhost
Origin: http://localhost
Pragma: no-cache
Referer: http://localhost/web/user/reset-pwd
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36
X-Requested-With: XMLHttpRequest
old_password: 123456
new_password: root123456
同样的方法,http://localhost/web/user/edit 就可以成功 post 。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
把这两句放在
actionResetPwd
方法里面,开启 报错,再请求查看一下报错信息500接口发出去了 就是后台的锅了
你在下后台相对应接口地方打个断点,看下报什么错