2012-10-05 15 views
6

Sto facendo un post chiamata jQuery in questo modo:Perché non riesco a vedere i dati JSON restituiti da PHP con post di jquery?

var t1 = $("#form").serialize(); 

    $.ajax({ 
     type: "POST", 
     url: "save_test.php", 
     data: t1, 
     cache: false, 
     success: function(data){ 

      if (data.st) { 
       alert("Success"); 
      } 
      else if (data.error) { 
       alert("Error"); 
      }     
     } 
    }); 

mio PHP Sembra che questo per la mia prova di errore:

$res = new stdClass(); 

$res->error = 'ERROR SEEN'; 
echo json_encode($res); 
exit(); 

dati Perché non è possibile accedere al mio JSON codificato restituito da PHP? Mi aspetto che questo attiverà il mio avviso data.error.

risposta

6

uso datatype:json nel codice jQuery

oppure è possibile utilizzare

var d=$.parseJSON(data) 

quindi utilizzare d.st

+1

che era, non ero l'analisi del JSON restituito da PHP. Grazie! – Paul

+1

@Paul, benvenuto – StaticVariable

Problemi correlati