Ver Mensaje Individual
  #12 (permalink)  
Antiguo 09/12/2013, 10:48
Avatar de adryan310
adryan310
 
Fecha de Ingreso: septiembre-2012
Mensajes: 450
Antigüedad: 11 años, 7 meses
Puntos: 3
Exclamación Respuesta: Cual es la forma correcta de recibir un dato por ajax en PHP ?

Amigo pongo lo de new Array(); y mas bien deja de funcionar. La variable esta llegando bien pero hay algo que yo estoy haciendo mal y no me esta funkando. Pongo aca todo mi cod y me dicen en que estoy fallando:

JS:
Código Javascript:
Ver original
  1. $(document).ready(function() {
  2.  
  3.     var array = new Object();
  4.     array['tag'] = "NFL";
  5.  
  6.     $.ajax({
  7.         type: "POST",
  8.         data: array,
  9.         url: 'livescore.php',
  10.     });
  11.  
  12. });
PHP:
Código PHP:
$response = array(); 
    if (isset (
$_POST['tag']) && $_POST['tag'] != '') { 
        
$response['tag'] = $_POST['tag'];  
        
error_log('tag: '.$response['tag']);  
    } 

        
print_r('response: '.$response);
          echo 
json_encode($response); 

      foreach (
$games as $group) {
          
         if(
$group['league'] == $response['tag']){ // ACA DEBO DE COMPARAR CON LA VARIABLE QUE VENGA DESDE EL JQUERY POR AJAX.
               
echo '<table class="item sporTitle '.str_replace(' '''$group['league']).'">';
             echo 
"<tr><td>".$group['league']."</td></tr>";
             echo 
"</table>";

               foreach (
$group['groupeddata'] as $gameDetails) {

                   if(
trim($gameDetails['status']) == ""){
                       echo 
'<table class="item empty '.str_replace(' '''$group['league']).'" title="'.$gameDetails['homeName'].' at '.$gameDetails['awayName'].'">';
                       echo 
"<tr><td>".$gameDetails['home']." @ ".$gameDetails['away']."</td></tr>";
                     echo 
"<tr><td>".$gameDetails['time']."</td></tr>";
                     echo 
"</table>";
                    }else{
                           
                           echo 
'<table class="item full '.str_replace(' '''$group['league']).'" title="'.$gameDetails['homeName'].' at '.$gameDetails['awayName'].'">';
                             echo 
"<tr><td class=\"team , teamHome\">".$gameDetails['home'].'</td>';
                                 echo 
"<td class=\"point pointHome\">".$gameDetails['hScores']."</td>";
                                 echo 
"<td class=\"status\" rowspan=\"2\">".$gameDetails['status'].'</td>';
                                 echo 
"</tr>";
                             echo 
"<tr><td class=\"team\">".$gameDetails['away'].'</td>';
                                 echo 
"<td class=\"point\">".$gameDetails['aScores'].'</td>'
                             echo 
"</tr>";
                           echo 
'</table>';

                        }
               }
           } 
     }