我想发送两个查询变量,并希望将这些值发送到jquery ajax数据值。现在我在ajax页面中什么都没有。如果我使用一个查询语句并传递一个值,我得到一些输出
$.ajax({
url: 'get-details',
type: 'GET',
data: 'id='+user_id,
dataType: 'JSON',
success: function(data,data1,textStatus, jqXHR){ //want to add data1
var id = data.id;
var alt=data1.column;
alert(data1.column);
},
error: function(jqXHR, textStatus, errorThrown){
},
});
public function getDetails(Request $request)
{
$request_data = $request->all();
$user_id = $request_data['id'];
$user_data =DB::table('travel_request')
->join('department', 'travel_request.department_id', '=', 'department.id')
->select('travel_request.*')->where('travel_request.id',$user_id)->first();
$req=DB::table('traveling_details')->select('traveling_details.*')->get(); //has multiple value
return response()->json($user_data,$req);
}
答案 0 :(得分:1)
如果有效,请尝试这样
$data['user_data'] = DB::table('travel_request')
->join('department', 'travel_request.department_id', '=', 'department.id')
->select('travel_request.*')->where('travel_request.id',$user_id)->first();
$data['req'] = DB::table('traveling_details')->select('traveling_details.*')->get(); //has multiple value
return response()->json($data);
你在视图文件中的ajax函数应该是这样的
$.ajax({
url: 'get-details',
type: 'GET',
data: 'id='+user_id,
dataType: 'JSON',
success: function(data){ //want to add data1
var user_data = data.user_data;
var req = data.req;
console.log(user_data);
console.log(req);
// to access the column of the user_data
var YourVariableName = user_data.ColumnNameHere;
},
error: function(jqXHR, textStatus, errorThrown){
},
});