결과 배열을 JSON 형식으로 인코딩하고 응답을 반환하십시오.
<?php
$arr = array ('response'=>'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 (data.response == 'captcha') {
alert('captcha');
} else if (data.response == 'success') {
alert('success');
} else {
alert('sorry there was an error');
}
}
});
</script>
개체 또는 배열에 포장하고 직렬화하여 보냅니다. – BlitZ
@CORRUPT - JS에서 어떻게 열 수 있습니까? – ShadowZzz