【发布时间】:2019-10-05 06:25:45
【问题描述】:
在我的页面中,我使用 ajax 从 db 获取数据,所以在我的控制器中,我检索两个数据,当我将它们发送到页面时,我只得到一个数据
这是我使用的方法 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(){
}
});
这是我在控制器中的功能
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']);
}*/
}
【问题讨论】:
-
当我只发送一个 id 时同样的问题
-
不工作,我的问题是如何从控制器 2 中获取数据,例如使用数组作为返回响应...