So I have this on the PHP side:
//enclosed in for loop start
$titleArray[] = $title;
$idsArray[] = $id;
//enclosed in for loop end
After the loop runs, the arrays are populated, here is a var_dump showing that. And then we json encode it and exit, sending it as a response for jQuery to handle.
var_dump($titleArray);
array(2) {
[0]=>
string(2) "T1"
[1]=>
string(2) "T2"
}
var_dump($idsArray);
array(2) {
[0]=>
string(2) "I1"
[1]=>
string(2) "I2"
}
$output = array('success' => true, 'type' => 'valid', 'titles' => ''.$titleArray.'', 'ids' => ''.$idsArray.'');
echo json_encode($output);
exit();
Here is where I run into the issue. I can't seem to access those arrays (titles/ids) anymore. The response is:
{"type":"valid","titles":"Array","ids":"Array"}
Here is the post success area to handle the response:
success: function(output) {
var x = $.parseJSON(output);
if(x.type=='valid'){
$.each(x.titles, function(k, v) {
$("#output-area").append('<div id="'+v.ids+'" class="title">Title: '+v.titles+'</div>');
});
}
}
2 new divs should be appended at this point, as there are 2 items in the arrays. Instead, I get 5 newly appended divs with undefined as the v.ids and v.titles values. How can I get the correct and desired output in this scenario?