我試圖從Laravel發送對AJAX發佈請求的響應。AJAX發送陣列作爲來自Laravel的響應
public function infoRoute(Request $request)
{
// Get info
$ship_id = $request->ship_id;
$startDate = $request->datepicker_start;
$endDate = $request->datepicker_end;
// Get all the locations between those dates
$routeArray = $this->measurementRepository->getCoordinates($ship_id, $startDate, $endDate);
$ship = $this->shipRepository->getShipForId($ship_id);
$info = $this->createRouteArrayForShip($ship, $routeArray);
if($request->ajax()) {
return response()->json(json_encode($info));
}
}
protected function createRouteArrayForShip($ship, $routeArray)
{
$info['type'] = "showRoute";
$index = 0;
foreach($routeArray as $coordinates)
{
$info['info']['route']['loc'. $index] = $coordinates;
$index++;
}
$info['info']['shipInfo'] = $ship;
//dd($info);
return $info;
}
當我收到信息並使用jQuery處理它時,除路由之外,所有內容都顯示爲空。
謝謝
如果您使用瀏覽器的開發者工具..什麼數據,你看回來的迴應? – Dale
你有一個多維數組在那裏.. –
試着把它作爲JSON返回 – kejsu