1
I’m having doubts about how to structure a JQuery that should append an HTML code to each of the items that a JSON returns to me. My question is how to retrieve each of the JSON values and make a repeat structure to create the HTML code that will finally be printed on the page. It’s all very simple because I’m learning to work with Phonegap. Thanks for your help.
For example: I want each item returned in JSON to create a Panel with the name of the country and championship as the hardcoded example of the image: 
webservice.js
function listaCampeonatos(){
$.ajax({
url: 'http://localhost/projetos/cjwebservice/listagem.php',
type: 'GET',
dataType: 'json',
data: {type:'listaCampeonatos'},
ContentType: 'application/json',
success: function(response){
alert('Listagem bem sucedida!');
$('#resultado').html(JSON.stringify(response));
},
error: function(err){
alert('Ocorreu um erro ao se comunicar com o servidor! Por favor, entre em contato com o administrador ou tente novamente mais tarde.');
console.log(err);
}
});
}
php listing.
include './conexao.php';
header("Access-Control-Allow-Origin: *");
$link = conectar();
if ($_GET['type'] == "listaCampeonatos") {
//echo 'Tipo de operação: ' . $_GET['type'] . '<br>';
$query = "SELECT c.id AS id_campeonato, c.nome_camp AS nome_campeonato, p.nome_pais AS nome_pais
FROM tb_campeonato c
LEFT JOIN tb_pais p ON p.id = c.tb_pais_id
LEFT JOIN tb_partida pt ON pt.tb_campeonato_id = c.id
WHERE pt.flag_ativo = 1
GROUP BY p.nome_pais";
$result = mysqli_query($link, $query);
$registros = array();
while ($reg = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$registros[] = array('Campeonatos' => $reg);
}
$saida = json_encode(array('Lista' => $registros));
echo $saida;}
html games.
<!-- COTAÇÕES INÍCIO -->
<div id="painel_partidas" class="panel panel-primary panel-heading-margin">
<div class="panel-heading">
<center>
<b>Brasil » Série A - 19/10/2016</b>
<button data-toggle="collapse" data-target="#partida" class="btn btn-default btn-xs pull-right"><i class="fa fa-compress"></i></button>
</center>
</div>
<div id="partida">
<div class="w3-border">
<center>
<button class="btn btn-xs btn-danger" onclick="listaCampeonatos()"><i class="fa fa-search"></i>
Testar JSON
</button>
</center>
<div id="resultado"></div>
<!--COTAÇÕES AQUI-->
</div>
</div>
</div>
<!-- COTAÇÕES FIM -->
from a console.log(Response) and see how this json is returned, put it tbm
– Gabriel Rodrigues
Log: Object {List: Array[2]} JSON: { "List":[ { "Championships":{ "id_championship":"630", "championship name":"World Cup r", "parentname":"Africa r" } }, ;{ "Championships":{ "id_championship":"11", "championship name":"Series A r", "parentname":"Brazil r" } } ] ;}
– Guilherme Ramalho