I am having trouble with my jQuery script below, this is a basic stripped down version and even it will not work, I have the php file that the jQuery script makes a call to, I have it set to encode and show a JSON response
Then in the jQuery script it should read the value and respond to it but It is not getting the response.
Is json.response
the wrong way to call a variable in the JSON string that is name response?
<?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:
I have changed
json.response
into
data.response
But this did not make it ork either
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…