I have one login.php, one main.php, one functions_js.js and one functions_php.php (I use jquery too).
My problem is I need to take two variables from login.php and send it to functions_php.php (ajax, ok that works) but then in functions_php.php I make a query select (with this variables) and it returns me an array which I need on functions_js.js , in this file I have a function to insert images on main.php. I don't know how to pass the array from functions_php to functions_js.js. I've read that I can use json but I don't know how to use between 2 different files.
I've tried to use json and pass it to main.php but no works:
functions_php.php:
if (isset($_POST['user'])) {
function startPerson($nick,$pass){
$query = $conexion->query('SELECT archive_id FROM family WHERE family_id=(select distinct family_id from person where user_id = (select user_id from user where user_name="'.$nick.'" and password="'.$pass.'"))');
$query->execute();
while ($res = $query->fetch()) {
$id = $res['archive_id']; //archive_id
}
//coger las personas de las familias de ese archive_id
$query = $conexion->query('SELECT person_id, birth_date FROM person WHERE family_id in (select family_id from family where archive_id='.$id.')');
$query->execute();
while ($res = $query->fetch()) {
$person[] = $res[0]; //archive_id
$date[]=$res[1];
}
return array($person, $date);
}
header('Content-Type: application/json');
$encoded=json_encode(startPerson($_POST['user'],$_POST['pass']));
echo $encoded;
}
main.php:
<?php
$json_data=json_encode($encoded);
?>
<script>
var an_obj= <?php echo $json_data;?> ;
alert(an_obj);//returns null
</script>
function_js.js:
function startPerson (date) {
for(i=0;i=>date.length;i++){
var elem = date[i].split('-');
var mon= elem[1]; //month
var year=elem[0]; //year
var mont= num2mon(mon);
position(year,mont);
elem=" ";
mon=" ";
year=" ";
}
}
function position(year, mon)
{
$('#' + year + ' .' + mon).prepend('<img class="black_point" src="./images/circle.png"/>');
}