dongzhimeng2464 2018-04-27 06:49
浏览 63
已采纳

在laravel中提交表单后,请记住滚动条位置

Is it possible to remember scrollbar position after form submit and returning back to the home page?

Here is my form:

<form method="post" action="{{Route('sites.liking')}}">
  <input name="_token" value="{{csrf_token()}}" type="hidden">
  <input type="hidden" value="{{$meme->likes}}" name="likes">
  <input type="hidden" value="{{$meme->id}}" name="likeid">
  <input type="hidden" value="{{Auth::user()->name}}" name="sendeduser">
  <button class="linking">+ {{$meme->likes}}</button>
</form>

Routing:

Route::post('/', ['uses' => 'LikingComments@liking', 'as' => 'sites.liking']);

Controller function:

public function liking(Request $request) {
  //Function guts
  return redirect('/')->with('status', $id);
}

I've tried several scripts but it always scrolls to the top of the page.

Is there a some way to go back to the same place of the page ?

  • 写回答

2条回答 默认 最新

  • dsgwdigu84950 2018-04-27 08:11
    关注

    Okay I've solved up that problem by adding an id to an element, new routing and changing main function.

    <div id="{{$meme->id}}">
     <form method="post" action="{{Route('sites.liking')}}">
      <input name="_token" value="{{csrf_token()}}" type="hidden">
      <input type="hidden" value="{{$meme->likes}}" name="likes">
      <input type="hidden" value="{{$meme->id}}" name="likeid">
      <input type="hidden" value="{{Auth::user()->name}}" name="sendeduser">
      <button class="linking">+ {{$meme->likes}}</button>
     </form>
    </div>
    

    Changed function:

    public function liking(Request $request)
    {
     //Function guts
    
    
     return redirect()->action('LikingComments@indexliking', ['id' => $id])->with('status', $id);
    }
    

    Routing:

    Route::get('/#{id}' , ['uses' => 'LikingComments@indexliking', 'as' => 'indexliking']);
    

    It don't work perfectly but it's fine for me. Thank you for your answers especially @kerbholz

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)