doulai8128 2016-07-13 02:59
浏览 43

如何使用jquery在索引方法上加载laravel中show方法的内容

i have two methods show and index i have a list of items on the index method that when a user clicks it takes her to another page containing some data that belongs to that id. instead of doing it such way i want to use jquery to achieve this, to make the data load on the same page. i have the following on my index.blade.php view, please how do i achieve this in laravel

       @foreach ($categories as $category)

        <div class="body">
        <h4><a style="text-decoration: none; " href="{{ URL::route('category.show', $category->id) }}">{{$category->name}}</a></h4>

        </div>
       @endforeach

    <?php
     namespace App\Http\Controllers;
     use Illuminate\Http\Request;
     use illuminate\HttpResponse;
     use App\Http\Requests\todolistRequest;
     use App\Http\Requests\CreateCategoryRequest;
     use App\Http\Requests;
     use App\Companylist;
     use App\Category;
     use  Illuminate\Support\Facades\DB;
     class CategoryController extends Controller
     {

public function create(){
    return view('category.create');
}

public function index(){
    $categories=Category::all();
    return view('category.index',compact('categories'));
}
public function store(CreateCategoryRequest $request){
     $category = new Category($request->all());
     $category->save();

      return \Redirect::route('category.create')->with('message',      'Your list has been created!'); 
}
      public function show($id)
      {
      $category = Category::findOrFail($id)->companylist()->get();
      $cat=Category::findOrFail($id);
    // this my route
    Route::resource('category','CategoryController');

    return view('category.show')->with('category',     $category)->with('cat',$cat);
 }


//
}
  • 写回答

1条回答 默认 最新

  • douyi02577 2016-07-13 06:07
    关注

    To show details data on index page without page refreshing , you should use ajax , in ajax return data and show it in index page ( i.e. under each list )

    In ajax you have to pass the id and depending on id return corresponding data.

    Hope it helps

    评论

报告相同问题?

悬赏问题

  • ¥15 python变量和列表之间的相互影响
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)