我正在使用Laravel框架。我被卡住了。我成功獲取數據。但是,當我想顯示數據時,它會以數組形式顯示我的數據。任何人都可以幫助我如何顯示清單。我有一個佈局內div
如何在div中顯示AJAX響應數據
<div class="col-md-9 col-sm-9 col-xs-12" id="ajaxListings">
@include('layouts.publicLayout.get-listings')// here i have implemented layout
</div>
和
function filteredlistings(){
$.ajax({
url:'search-listings',
data:{
'service_name':title,
'location':location
},
type:"get",
success:function(allData)
{
$("#ajaxListings").html(allData);
},
error: function()
{
alert('error');
}
});
}
這裏是我的功能:
public function search_listings(Request $request){
if($request->ajax()){
$data = $_GET;
$users = DB::table('users')
->join('business_services', 'users.id', '=', 'business_services.user_id')
->join('listings','users.id', '=', 'listings.user_id')
->select('users.id', 'business_services.name', 'business_services.list_id','listings.location')
->where(['business_services.name'=>$data['service_name'],'users.service_name'=>"Seller"])
->where('listings.location','like','%'.$data['location'].'%')
->get();
$users = json_decode(json_encode($users),true);
foreach($users as $alluser){
$ids[] = $alluser['id'];
}
$allData="";
if(!empty($ids)){
$allData = User::with('listings')->whereIn('id',$ids)->get();
$allData = json_decode(json_encode($allData),true);
}
$title = "Nails";
echo "<pre>"; print_r($allData); die;
}
}
它看起來像你的服務器正在返回信息作爲一個數組。您可能需要遍歷響應並構建您的html。 –
你想要的輸出是什麼? –
我想在佈局 – kunal