duanjiyun7391 2018-01-23 08:23
浏览 59

Laravel ajax显示他获取到另一个表的所有数据

I need some help from you guys because i don't have any idea how to display all data-form my ajax there's some image and you will know what is my problem by the way im a fresh programmer and want to be like you guys

Display ajax result

Someone can teach me how to display all ajax data-form

Here is my ajax code

$(".ajaxForm").submit(function(e) {
e.preventDefault();    
var formData = new FormData(this); 
$.ajax({
    url: 'cart',
    type: 'POST',
    data: formData,
    success: function(data) {
        console.log(data);
    },
    cache: false,
    contentType: false,
    processData: false
});
});

And here is my view page code

                 <tbody>
                    @foreach($customers as $name => $member)
                     @foreach($member->slice(0,1) as $value)
                     <tr>
                         <td>{{$value->id}}</td>
                         <td>{{$value->MATNR}}</td>
                         <td>{{$value->MAKTX}}</td>
                         <td>
                           <select class="form-control">
                              <option>{{$value->UNIT1}}({{$value->CONV1}})</option>
                              <option>{{$value->UNIT2}}({{$value->CONV2}})</option>
                          </select>
                         </td>
                         <td>{{$value->VERME}}</td>
                         <td>
                            <form method="POST" id="ajaxForm" class="form-horizontal ajaxForm">
                           <select class="form-control" name="CHARG">
                            @foreach($member as $value)
                              <option value="{{$value->CHARG}}">{{$value->CHARG}}</option>
                            @endforeach
                          </select>
                         </td>
                         <td>
                            <input type="hidden" id="token" name="_token" value="{{ csrf_token() }}">
                            <input type="hidden" name="id" id="id" value="{{$value->id}}"> 
                            <input type="hidden" name="MATNR" value="{{$value->MATNR}}">
                           <button>Submit</button>
                         </form>
                         </td>
                    </tr>
                     @endforeach 
                    @endforeach  
                    </tbody>

Controller code

  public function gen_request() // this function is to view all the record from database 
{   
    $id = Auth::user();
    $customers = DB::table('Customers')->select('users.id','users.name','users.email','Customers.Index','Customers.NAME1','Materials.MAKTX','Materials.MAGRV','Materials.CONV1','Materials.id','Materials.CONV1','Materials.UNIT1','Materials.CONV2','Materials.UNIT2','Materials.MHDHB','Inventory.CHARG','Inventory.MATNR','Inventory.VERME')->join('users','users.company_id','=','Customers.Index')->join('Inventory',function($join){

    $join->on('Inventory.MATNR','LIKE', DB::raw("CONCAT('%',Customers.KUNNR,'%')"));

    })->join('Materials',function($join){

    $join->on('Materials.MATNR','LIKE', DB::raw("CONCAT('%',Inventory.MATNR,'%')"));

    })->where('users.id', Auth::id())->groupBy('users.id','users.name','users.email','Customers.Index','Customers.NAME1','Inventory.MATNR','Materials.MAKTX','Materials.MAGRV','Materials.CONV1','Materials.id','Materials.CONV1','Materials.UNIT1','Materials.CONV2','Materials.UNIT2','Materials.MHDHB','Inventory.CHARG','Inventory.VERME')->get()->groupBy(function ($member){
        return $member->MATNR;
    })->all();

    $cart = ShoppingCart::all();
    return view('system/request',compact('customers','cart'));
}


public function cart() // and this will be cart function
    {
    if (Request::isMethod('post')) {
        $id = Request::get('id'); 
            $customers = DB::table('Materials')->select('Materials.MATNR','Materials.MAGRV','Materials.CONV1','Materials.id','Materials.CONV1','Materials.UNIT1','Materials.CONV2','Materials.UNIT2','Materials.MHDHB','Materials.MAKTX','Inventory.CHARG','Inventory.VERME')->join('Inventory',function($join){
                $join->on('Inventory.MATNR','LIKE',DB::raw("CONCAT('%',Materials.MATNR,'%')"));
            })->groupBy('Materials.MATNR','Materials.MAGRV','Materials.CONV1','Materials.id','Materials.CONV1','Materials.UNIT1','Materials.CONV2','Materials.UNIT2','Materials.MHDHB','Materials.MAKTX','Inventory.CHARG','Inventory.VERME')->find($id);

       $cart = ShoppingCart::add($customers->id, $customers->MATNR, 5, 100.00, ['MATNR' => $customers->MATNR,'VERME' => $customers->VERME, 'CHARG' => $customers->CHARG]);
        if($cart){
            response()->json(array('message'=>'Aritcle Save Successfully'));
        }else {
                response()->json(array('message'=>'Article failed to save'));
            }
       }   
}

I want to display them to another table but the problem is i dont any idea how to retrieve that record:

I want to display them to another table but the problem is i dont any idea how to retrieve that record

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 matlab有关常微分方程的问题求解决
    • ¥15 perl MISA分析p3_in脚本出错
    • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算
    • ¥15 java如何提取出pdf里的文字?
    • ¥100 求三轴之间相互配合画圆以及直线的算法
    • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
    • ¥15 名为“Product”的列已属于此 DataTable