在blade中,使用ajax提交数据
前端提交数据代码
<script type="text/javascript" src="/js/jquery.min.js"></script>
//ajax发送数据
$.ajax({
headers: {'X-CSRF-TOKEN': "{{ csrf_token() }}" },
url: "{{ route('hexiao.tijiaoshangpin') }}",
type: "post",
data: {
shangpin_id: currentProduct.id,
phone:phone,
address:address,
duihuanjifen:currentProduct.points,
kahao:{{ session('res')->kahao }}
}).done(function(data) {
console.log(data);
alert(data.message);
window.history.go(-1);
}).error(function(data) {
console.log('兑换失败'+data);
});
//数据发送结束
后端代码:
public function editPasswordTijiao(Request $request){
$xiugai=DB::table('cbsy_hexiao_ma')
->where('kahao', $request->kahao)
->where('password',$request->jiu)
->first();
if( $xiugai ){
$a = DB::table('cbsy_hexiao_ma')->where('kahao', $request->kahao)->update(['password' => $request->xin]);
if($a){ $msg='修改成功';}
else{ $msg='修改失败';}
}else{
$msg='旧密码不正确';
}
$data = [
'code'=>200,
'message'=>$msg
];
return response()->json($data,200);
}
最近访问时间:2025-09-17 17:26:53