jquery - 我如何使用ajax将多个数据从 Controller 发送到页面html

标签 jquery mysql ajax laravel

在我的页面中,我使用ajax从数据库获取数据,所以在我的 Controller 中,当我将它们发送到页面时,我检索了两个数据,我只得到一个数据

这是我用过的ajax方法

$.ajax({
    type:'get',
    url:'{!!URL::to('gestion_commandes/create/gencodesol1')!!}',
    data:{'id':type, 'id':code},
    dataType:'json',
    success:function(data){
        console.log('success');
        console.log(data);
        console.log(data.nbrdebut);
        //console.log(data.type);

      /* var codesol=data+data.nombre;
        for(y=1;y<=nbrrowsol;y++ ){
           var somme=codesol+y;
        $('#codesol'+y).val(somme);
        console.log(somme);
        }*/
    },
    error:function(){

    }
});

这是我在 Controller 中的功能

 public function findnaturesol1(Request $request)
    {
        $data=Commande::select('nombre')->where('code', 'LIKE', '%'.$request->id.'%')->count();
        if($data!=0){
            //$data1=Commande::select('select code from commandes ')->where('code','LIKE', '%'.$request->id.'%')->count();

           // $data=Matrice::select('nbrdebut')->where('type',$request->id)->first(); 
           //  $data=$vide1+$data2;
           // echo '$data2->$nbrdebut';
            return response()->json($data);
        }
        /*else{
            $data=DB::table('commandes')-insertGetId(['code' => 'first']);
        }*/


    }

最佳答案

这是我的代码抱歉我忘了评论标记

public function findnaturesol1(Request $request)
    {
        $data=Commande::select('nombre')->where('code', 'LIKE', '%'.$request->id.'%')->count();
        if($data!=0){
            //$data1=Commande::select('select code from commandes ')->where('code','LIKE', '%'.$request->id.'%')->count();

            $data=Matrice::select('nbrdebut')->where('type',$request->id)->first(); 
           //  $data=$vide1+$data2;
           // echo '$data2->$nbrdebut';
            return response()->json($data);
        }
        /*else{
            $data=DB::table('commandes')-insertGetId(['code' => 'first']);
        }*/


    }

关于jquery - 我如何使用ajax将多个数据从 Controller 发送到页面html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56194576/

相关文章:

mysql - 如何捕获 Grails 中的约束(索引)违规?

javascript - 无法访问 JavaScript 属性

php - 如何使用 jquery ajax 将 php 关联数组附加到 html

mysql - 如果另一个字段为空,则将字段更新为空或删除行

javascript - 将数组从一个 php 页面传递到另一个 javascript 页面的最佳实践?

javascript - 我没有收到 Google Books API 的响应?

ajax - 单页多个表单的优雅解决方案

jquery - 从 jquery 片段中删除函数有困难

javascript - 从arraybuffer显示pdf

mysql - 查询为空时如何显示内容?