I am trying to parse information that is returned from a DB and encoded into a JSON object.
this is the code that retrieves the information:
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; }
and this identifier, as I try to parse the information:
$.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']) }); } });
I tried several different ways to do this, but I only ever get [object] [object] as an answer.
this is the answer:
http://i.imgur.com/E5Hux.png
source share