DB에서 반환되고 JSON 객체로 인코딩 된 정보를 구문 분석하려고합니다.JSON 객체를 Ajax를 통해 전달합니다.
$.ajax({
type: "POST",
url: "lib/search/search.standards_one.php",
async: "false",
data: {subjects: subjects, grades: grades},
success: function(response){
$("#standards_results").html("");
var obj = $.parseJSON(response);
$.each(obj, function(){
alert(this['code'] + ", " + this['standard_one_id'])
});
}
});
나는 다양한 방법을 시도했습니다 :
private function retrieve_standards_one(){
$dbh = $this->connect();
$stmt = $dbh->prepare("SELECT code, standard_one_id
FROM standard_one
WHERE grade_id = :grade_id
ORDER BY standard_one_id");
$stnd = array();
for($x = 0; $x < (count($this->grades)); $x++){
$stmt->bindParam(':grade_id', $this->grades[$x], PDO::PARAM_STR);
$stmt->execute();
$stnd[] = $stmt->fetchAll(PDO::FETCH_ASSOC);
}
$json = json_encode($stnd);
return $json;
}
내가 정보를 분석하기 위해 노력하고있어 방법이 ID :
이
는 정보를 검색하는 코드입니다 이것을해라. 그러나 나는 단지 [object] [object]를 응답으로 얻는다.
'[개체 개체]'개체의 기본 문자열 표현이 너무 코드가 아마 제대로 작동이다.'alert'는 ** 아주 나쁜 ** 디버깅 도구입니다 –
consol.log는 여전히 [objects]를 반환합니다. – Brendan
문자열 연결을 제거 했습니까? console.log (예 : ..이 [ '코드']);을 console.log (이 [ 'standard_one_id'])'당신은 피해야한다 무엇 인 문자열로 오브젝트를 변환합니다 모두,'alert' 및 문자열 연결은 –