내 PHP (SLIM 프레임 워크)가 JSON 파일을 생성 중입니다. JSON 검사기에서 파일을 검사했는데 모든 것이 정상입니다. index.html
, 내 로컬 AngularJS 주 파일을 브라우저에 입력하면 자동으로 JSON 파일이 표시되지 않지만 파일을 열거 나 저장할지 묻습니다. 저는 Xampp의 Apache 가상 호스트 인 MySQL을 사용하고 있습니다. 브라우저에서 파일을 로컬에 저장하지 않고 JSON을 표시하면 프로젝트를 완료하고 도메인에 연결하면 아무나 자신의 컴퓨터에 JSON 콘텐츠를 표시 할 수 있습니다.브라우저에서 자동으로 JSON 콘텐츠를 표시하지 않습니다.
`<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
$app = new \Slim\App;
// Get All Customers
$app->get('/api/calendar', function (Request $request, Response $response) {
// echo 'CALENDAR'; });
$sql = "SELECT * FROM days";
try {
// Get DB Object
$dbcalendar = new dbcalendar();
//Connect
$dbcalendar = $dbcalendar->connect();
$stmt = $dbcalendar->query($sql);
$dbcalendar = $stmt->fetchAll(PDO::FETCH_OBJ);
// $dbcalendar = null;
return $response->withJson($dbcalendar);
} catch(PDOException $e) {
$error = array('error' => array('text' => $e->getMessage()));
return $response->withJson($error,500);
}
});`
OK :
이
는 PHP 파일입니다. 나는 프레드 제안에 따라 PHP 파일을 바꿨다. (정확히 바란다) :`<?php
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
$app = new \Slim\App;
// Get All Customers
$app->get('/api/calendar', function (Request $request, Response $response) {
// echo 'CALENDAR'; });
$sql = "SELECT * FROM days";
try {
// Get DB Object
$dbcalendar = new dbcalendar();
//Connect
$dbcalendar = $dbcalendar->connect();
$stmt = $dbcalendar->query($sql);
$dbcalendar = $stmt->fetchAll(PDO::FETCH_OBJ);
// $dbcalendar = null;
return $response->withJson($dbcalendar);
header('Content-type: application/json');
} catch(PDOException $e) {
$error = array('error' => array('text' => $e->getMessage()));
return $response->withJson($error,500);
}
});`
그러나 여전히 변화가 없다.
일부 코드를 제출하십시오 –
브라우저에 json 파일의 올바른 승인 및 콘텐츠 유형 헤더를 보내시겠습니까? (힌트 : application/json) – RichardAtHome