여기에 전체 코드가 나와 있습니다. 오류는 jsonTesting.php 페이지에 문학, 역사 및 코미디 변수가있는 것으로 보입니다.이 변수는 정의되어 있지 않습니다. 이러한 변수는 아약스의 게시물이어야합니다. 도와주세요 asap.here 내 PHP 페이지 (jsonTesting.php)입니다 :json에서 ajax 및 php를 사용하는 구문 오류
<?php
$library=
'{"closets":[
{"id":"001","theme":"literature","shelves":
{
"books": [{"id":"b1","genre":"english Literature"},
{"id":"b2","genre":"arabic literature"},
{"id":"b3","genre":"french literature"}
]
}
},
{"id":"002","theme":"comedy","shelves":{
"books":[{"id":"b11","genre":"english comedy"},
{"id":"b22","genre":"arabic comedy"},
{"id":"b33","genre":"french comedy"}
]
}
},
{"id":"003","theme":"history","shelves":{
"books":[{"id":"b111","genre":"english history"},
{"id":"b222","genre":"arabic history"},
{"id":"b333","genre":"french history"}
]
}
}
]
}';
//isset is used to make sure that we are reciving the post from the ajax
if(isset($_POST["literature"]))
$literature=$_POST["literature"];
if(isset($_POST["comedy"]))
$comedy=$_POST["comedy"];
if(isset($_POST["history"]))
$history=$_POST["history"];
$library = json_decode($library, true);
$literatureBooks = $library['closets'][0]['shelves']['books'];
$comedyBooks= $library['closets'][1]['shelves']['books'];
$historyBooks= $library['closets'][2]['shelves']['books'];
if($literature)
{
echo json_encode($literatureBooks);
exit();
}
if ($comedy){
echo json_encode($comedyBooks);
exit();
}
if($history){
echo json_encode($historyBooks);
exit();
}
?>
jsonTesting.php에서 json 응답 데이터를 확인하십시오. – kamesh