Hello! I'm trying to pull data from an API I made in PHP to send in JSON to another website. I was able to pull the result of an entire employee table, however now I want when I click on the employees to appear the other data related to it as Phone, address ... pulling by the id of it.
The API that links index.html
<?php
require_once 'bd2.php';
header('Access-Control-Allow-Origin:*');
$pdo = conectar();
$listar = $pdo->query("select * from funcionarios");
echo json_encode($listar->fetchAll(PDO::FETCH_OBJ));
?>
The javascript that does the JSON of index.html
$(document).ready(function(){
var container = $("#teste2");
var lista = container.find("#lista");
var html = '';
$.getJSON('http://teste.com/api-home.php', function(data){
$.each(data, function(k, v){
html += '<p>Nome: '+v.nome+'</p>';
html += '<p>E-mail: '+v.email+'</p>';
html += '<a href="perfil.html?id='+v.id+'">Perfil</a>'
});
lista.html(html);
});
});
The profile API that connects to the .html profile
<?php
require_once 'bd2.php';
header('Access-Control-Allow-Origin:*');
$pdo = conectar();
$id = $_GET['id'];
$listar = $pdo->query("select * from funcionarios where id='$id'");
echo json_encode($listar->fetchAll(PDO::FETCH_OBJ));
?>
The javascript that makes the JSON profile.html
$(document).ready(function(){
var container = $("#teste5");
var lista = container.find("#lista2");
var html = '';
$.getJSON('http://teste.com/api-perfil.php', function(data){
$.each(data, function(k, v){
html += '<p>Telefone: '+v.telefone+'</p>';
html += '<p>Endereço: '+v.endereco+'</p>';
});
lista.html(html);
});
});