Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

javascript - Laravel refresh data after ajax

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?

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());

}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>
...

And

table.blade.php:

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

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:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...