1
I’m consuming a Webservice on a client’s website.
i get the url return, filter the way I need, to display only the championships on condition:
"SEX : M "
"MODALITY : 2"
"CATEGORY : 4"
Being all true, returns me the name of the correct championship, only that is returning the following error:
Uncaught SyntaxError: Unexpected token <
In the following line:
"var html = '<a class="list-group-item list-group-item-action active" data-toggle="list" href="#home" role="tab">'+<td>1ª Fase</td><td>CIRCUITO ESCOLAR - SÉRIE OURO</td>+'</a>';"
I’ve tried writing in other ways, concatenate, and none of the error go away, please could help me?
php test.
<?php
$api_request = 'https://sportsmanager.com.br/api/[email protected]&token=2HSDE78623GVS7234GNMSKL';
$api_response = wp_remote_get( $api_request );
$api_data = json_decode( wp_remote_retrieve_body( $api_response ), true );
$retorno = '';
if($api_data){
foreach($api_data as $row){
if(!is_array($row)){
//$retorno = $retorno.'<td>'.$row.'</td>';
}else{
if($row['sexo'] == 'M' && $row['modalidade'] == 2 && $row['categoria'] == 4){
$retorno = $retorno.'<td>'.$row['nome'].'</td>';
}
}
}
}
jQuery
$(function(){
var html = '<a class="list-group-item list-group-item-action active" data-toggle="list" href="#home" role="tab">'+<?php echo $retorno;?>+'</a>';
$('#myList').html(html);
});
You are creating the wrong html, it has to be all within a single quote ''.
– LeAndrade