Laravel在ajax之后刷新数据 [英] Laravel refresh data after ajax

查看:147
本文介绍了Laravel在ajax之后刷新数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

他目前正在研究必须过滤表格中数据的代码。 Ajax将调用该链接并获得响应(json)结果和答案。但是,我遇到了一个问题。我必须以某种方式呈现表格,我不想通过追加等来做到这一点。

He is currently working on code that has to filter the data in the table. Ajax will call the link and gets the response (json) results with answer. However, I came across a problem. I have to somehow render tables and I do not want to do this by append etc.

我可以以某种方式再次生成视图或刀片文件吗?

Can I somehow again generate views or blade file?

默认视图是DefController @ index但是ajax使用url哪个控制器是DefController @ gettabledata。

The default view is DefController@index but ajax use url which controller is DefController@gettabledata.

public function gettabledata($id){

    return response()->json(Def::find($id)->getallmy->all());

}


推荐答案

你可以将表中的部分放在单独的 .blade.php 文件中的表格中,并将 @include 放入你的主要布局。

You can put the part in your template corresponding to the table in a separate .blade.php file, and @include that in your main layout.

main.blade.php

<html>
...
<body>
  <div class="table-container">
  @include('table')
  </div>
</body>
...

table.blade.php

<table>
  @foreach($rows as $row)
    <tr>
      <td> $row->title ... </td>
    </tr>
  @endforeach
</table>

这样你就可以使用一个简单的jQuery $('div.table -container')。load(url)并在您的服务器上呈现并将该部分作为html字符串进行响应。 返回视图('table',$ data)

In this way you can use a simple jQuery $('div.table-container').load(url) and on your server just render and respond that part as an html string. return view('table', $data)

Javascript:

Javascript:

function refreshTable() {
  $('div.table-container').fadeOut();
  $('div.table-container').load(url, function() {
      $('div.table-container').fadeIn();
  });
}

这篇关于Laravel在ajax之后刷新数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆