Doubt Syntax error in PHP / jQuery function

1

I'm consuming a Webservice on a client's website. I get the url return, filter the way I need it, to display only the championships with the condition:
"SEX: M"
"MODALITY: 2"
"CATEGORY: 4"
Click here to visit our advertiser. All of this is true, I get the correct championship name, but it is returning the following error:

Uncaught SyntaxError: Unexpected token <

On 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 already tried to write in other ways, to concatenate, and nothing of the error disappears, could you please help me?

test.php

<?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);
	  	
	});
    
asked by anonymous 30.07.2018 / 21:19

1 answer

1

The correct one would be:

$(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 do not need to concatenate the javascript string because php acts on the server and renders the html right there.

    
30.07.2018 / 21:47