I have "conditional content" base on the type of content, like so:
//--- Here goes a nice SQL where I get the content, this works ok. ---
if(mysqli_num_rows($niceSQL) > 0) {
while($something = mysqli_fetch_array($niceSQL)) {
$type = $something["type"];
if ("type" == "A") {
$data1 = $something["data1"];
$data2 = $something["data2"];
$data3 = $something["data3"];
$something_A = array(
"one" => $data1,
"two" => $data2,
"three" => $data3,
);
echo json_encode($something_A, JSON_FORCE_OBJECT);
} else if ("type" == "B") {
$data1 = $something["data1"];
$data2 = $something["data2"];
$data3 = $something["data3"];
$something_B = array(
"one" => $data1,
"two" => $data2,
"three" => $data3,
);
echo json_encode($something_B, JSON_FORCE_OBJECT);
}
}
}
I'm trying to dump every array as JSON for handle it with jQuery Each.
The problem is all that gets "printed" (echoed) at same time, so the AJAX response is "parsererror". I get this error in this way:
(ajax and config here).fail(function( jqXHR, textStatus ) {
console.log( "Request failed: " + textStatus );
})
So, how can I print every $something_A
or $something_B
independently but together? Together means only one ajax request, so I can handle the content with jQuery Each.
If I print only the first $something_A
or the first $something_B
then I can do the "each" loop (that's why I assume the PHP "json_encode" function is working properly), but it's not useful to me (because I'm receiving only the 1st of many "somethings").
Note: I can change the logic of the dumping, not how I get the content (SQL + while).