以laravel框架为例,直接上代码:
html:
<form action="/comment/destination" method="post">
{{csrf_field()}}
<input type="hidden" name="url" value="http://{{$_SERVER['HTTP_HOST']}}{{$_SERVER['REQUEST_URI']}}">
<input type="text" value="zhangsan">
<input type="submit" value="submit">
</form>
controller:
public function getResource(){
return view('home.test');
}
public function postDestination(Request $request){
$data=$request->url;
echo '<script>alert("登录成功");window.location.href="'.$data.'"</script>';
}