I am currently trying to send a 2d array that i receive from a database (sql, phpmyadmin) with ajax.
My ajax function looks like this: (it is generated in php)
$.ajax({
type: \"POST\",
url: \"resultQuizGet.php\",
data: \"getAnswer=\"+question+\"\", //question is just a int variable
success: function(msg) {
alert(\"Data Saved: \" + msg);
}
});
my resultQuizGet.php file then look like
$sql = "SELECT `quiz`.question,`quiz`.rightAnswer
FROM `quiz`
WHERE `quiz`.quizID=:qID";
$stmt = $dbh->prepare($sql);
$stmt->bindParam(":qID", $_POST['quiz']);
$stmt->execute();
$resultsQuiz = $stmt->fetchAll();
echo ...
What do i have to do now to receive a 2d array instead of just a normal string.
What i would like to the msg variable to be is a 2d array that is equal to $resultsQuiz
json_encodeto pass it as a structured array to your ajax call. Then, in your jQuery, use$.parseJSON()to convert it from the json string to an array.