'jquery 'ajax를 사용하여 laravel 컨트롤러에서 데이터를 가져 오려고합니다. 그러나, 나는 parsererror
을 얻고있다. laravel 문서에 따르면, 우리가 response()->json(data)
를 사용하는 경우 자동으로 헤더 Content-Type= 'application/json'
을 설정하고, 나도 아약스 측면에서 동일한 헤더를 설정했지만, 더 있을텐데요도 'jquery' 'aja'x 파서 오류가 발생했습니다. 데이터를 래 러블 컨트롤러에서 가져 오는 중입니다.
contentType:'application/json',
dataType: "json",
accept:'application/json',
을 시도하지하지만 그들 중 비는했다. 다음은 내 코드 설정입니다.
app.js
var initlides = function() {
return $.ajax({
url: _url,
contentType:'application/json',
dataType: "json",
accept:'application/json',
success: function (data) {
console.log(data)
},
error: function (textStatus, errorThrown) {
console.log(textStatus, errorThrown)
}
});
};
controller.php
public function index()
{
echo $section;
$carousels= array();
$carousel = Carousel::where('section_name', 'intro')->get();
return response()->json($carousel);
}
다른 유사한 질문을했지만 그 중 도움이되지 않았습니다. 도와주세요.
$carousel = Carousel::where('section_name', 'intro')->get()->toArray();
return response()->json($carousel);
또는 그냥 할 :
$carousel = Carousel::where('section_name', 'intro')->get();
return $carousel->toArray();
했던 –
경로의 방법 (게시/가져 오기/가져 오기 등 ...)은 무엇입니까? –
예 json 데이터와 GET 메서드를 반환하는지 확인했는데 – CodeBlooded