Ho problemi con il mio script jquery di seguito, questa è una versione ridotta di base e anche non funzionerà, ho il file php che lo script jquery effettua una chiamata per, ho impostato per codificare e mostrare una risposta JSONCome ottenere risposta jSON in variabile da uno script jquery
Quindi nello script jquery dovrebbe leggere il valore e rispondere ad esso ma non ottiene la risposta.
json.response è il modo sbagliato di chiamare una variabile nella stringa json che è la risposta del nome?
Qualcuno può aiuto per favore io sono bloccato
<?PHP
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-type: application/json');
// set to retunr response=error
$arr = array ('resonse'=>'error','comment'=>'test comment here');
echo json_encode($arr);
?>
//the script above returns this:
{"response":"error","comment":"test comment here"}
<script type="text/javascript">
$.ajax({
type: "POST",
url: "process.php",
data: dataString,
dataType: "json",
success: function (data) {
if (json.response == 'captcha') {
alert('captcha');
} else if (json.response == 'error') {
alert('sorry there was an error');
} else if (json.response == 'success') {
alert('sucess');
};
}
})
</script>
UPDATE;
ho cambiato
json.response
in
data.response
Ma questo non ce l'ha fatta ork sia
Ho appena provato, ma non ha fatto un altro – JasonDavis
puoi controllare di che tipo sono i tuoi dati. 'alert (typeof data);' nel callback di successo dovrebbe farlo. – RaYell
dice "oggetto" – JasonDavis