아래의 jquery 스크립트에 문제가 있습니다.이 스크립트는 기본 버전에서 제외되었으며 심지어 작동하지 않습니다. jquery 스크립트가 호출하는 PHP 파일이 있습니다. to, 인코딩하고 json 응답을 표시하도록 설정했습니다.jquery 스크립트에서 변수에 jSON 응답을 얻는 방법
그런 다음 jquery 스크립트에서 값을 읽고 응답해야하지만 응답을받지 못합니다.
json.response가 이름 응답 인 json 문자열에서 변수를 호출하는 잘못된 방법입니까?
는 누군가의 도움이 나는
<?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 붙어 있어요시겠습니까; 내가
data.response
에
json.response
을 변경 한 그러나 그것은 오크 중 하나
방금 시도했지만 다른 것을 만들지 않았 음 – JasonDavis
데이터 유형을 확인할 수 있습니까? 'alert (typeof data);'성공 콜백에서이를 수행해야합니다. – RaYell
그것은 "object"라고 말합니다 – JasonDavis