动态加载数据的引导模态与AJAX的帮助 - Laravel

问题描述:

页:default.blade.php动态加载数据的引导模态与AJAX的帮助 - Laravel

你好,我想要的是,当我点击显示按钮,下面的模式应该打开,什么,它应该包含数据库中的数据并通过ajax,所以请在这里帮助我。任何帮助,高度赞赏。

<div class="container"> 
      <table class="table"> 
         <thead> 
         <tr> 
          <th>#</th> 
          <th>Name</th> 
          <th width="300">Adress</th> 
          <th>Contact</th> 
          <th>Email</th> 
          <th>Phone</th> 
          <th>Show</th> 
          <th>Edit</th> 
          <th>Delete</th> 

         </tr> 
         </thead> 
         <tbody> 


        @foreach ($usertoshow as $us) 

         <tr> 
         <td>{{$us->u_id}}</td> 
         <td>{{$us->u_name}}</td> 
         <td>{{$us->u_add}}</td> 
         <td>{{$us->u_contact}}</td> 
         <td>{{$us->u_eml}}</td> 
         <td>{{$us->u_phn}}</td> 
         <td> 
          <button type="button" class="btn btn-xs btn-success" data-toggle="modal" data-target="#clientInfo" id="showButton"><span class="glyphicon glyphicon-th"></span> **Show**</button> 
         </td> 
         <td> 
          <button type="button" class="btn btn-xs btn-info"><span class="glyphicon glyphicon-pencil"></span> Edit</button> 
         </td> 
         <td> 
          <button type="button" class="btn btn-xs btn-danger"><span class="glyphicon glyphicon-remove-sign"></span> Delete</button> 
         </td> 

         </tr> 

         @endforeach 

         </tbody> 

       </table> 

      </div> 

代码莫代尔是

<div class="modal fade" id="clientInfo" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> 
     <div class="modal-dialog"> 
     <div class="modal-content"> 
      <div class="modal-header"> 
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button> 
      <h4 class="modal-title" id="myModalLabel">Modal title</h4> 
      </div> 
      <div class="modal-body"> 

      <div class="alert alert-info" role="alert"> 
      Name: <strong></strong> 
      </div> 

      </div> 
      <div class="modal-footer"> 
      <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
      </div> 
     </div> 
     </div> 
    </div> 

控制器

<?php namespace App\Http\Controllers; 

use App\Http\Requests; 
use App\Http\Controllers\Controller; 

use Illuminate\Http\Request; 
use App\User; 
use View, 
    Response, 
    Validator, 
    Input, 
    Mail, 
    Session; 



class UserController extends Controller { 

    /** 
    * Display a listing of the resource. 
    * 
    * @return Response 
    */ 
    public function index() 
    { 
     $usertoshow = User::all(); 
     return view('pages.default')->with('usertoshow',$usertoshow); 
    } 

    /** 
    * Show the form for creating a new resource. 
    * 
    * @return Response 
    */ 
    public function insert() 
    { 

     $user = User::create(['u_name' => Input::get('inputName'), 'u_eml' => Input::get('inputMail'), 'u_srname' => Input::get('inputsurName'),'u_add' => Input::get('inputAdd'),'u_phn' => Input::get('inputPhone'),'u_contact' => Input::get('inputContact')]); 

    } 

    /** 
    * Store a newly created resource in storage. 
    * 
    * @return Response 
    */ 
    public function showdetail() 
    { 


    } 

    /** 
    * Display the specified resource. 
    * 
    * @param int $id 
    * @return Response 
    */ 
    public function show($id) 
    { 
     // 
    } 

    /** 
    * Show the form for editing the specified resource. 
    * 
    * @param int $id 
    * @return Response 
    */ 
    public function edit($id) 
    { 
     // 
    } 

    /** 
    * Update the specified resource in storage. 
    * 
    * @param int $id 
    * @return Response 
    */ 
    public function update($id) 
    { 
     // 
    } 

    /** 
    * Remove the specified resource from storage. 
    * 
    * @param int $id 
    * @return Response 
    */ 
    public function destroy($id) 
    { 
     // 
    } 

} 

的代码您需要之前添加一个模式为每一个 “秀” 你的 @添加的foreach(incude文件做模态代码)在genModal
一些这样的事

@include ('layouts.modals.genModal' , ['record' => $us]) 

<div class="modal fade" 
    id="show-form{{{ $record->id }}}" tabindex="-1" role="dialog" 
    aria-labelledby="myModalLabel" area-hidden="true" 
    style="display: none;" > 

....模态的东西RES

,改变你data-traget与我们相同id

<button type="button" class="btn btn-xs btn-success" 
    data-toggle="modal" data-target="#clientInfo" 
    id="showButton"> 
    <span class="glyphicon glyphicon-th"></span> **Show** 
</button> 

data-target="#show-form{{{ $record->id }}}" 

将为show /编辑/删除,验证是不是那么容易,如果有人在那里有一个解决方案,请告知。

+0

你好@John Rankin和我得到你,但我仍然没有得到有关控制器的想法,它将如何将数据发送到控制器使用Ajax和控制器将如何返回该数据,谢谢 – Siddharth 2015-03-04 18:13:59