바이올린 : http://jsfiddle.net/wy4wd/19/예기치 않은 결과
내가 JSON 개체를 구문 분석하고 있지만,이 때 ID not found
을해야 Error
인 html로 초래되는 사람에 이르기까지 떨어지고 나는 이유를 알아낼 수 없습니다 .
success
이 1
인 경우 제대로 작동합니다.
JSON은 게시물 요청에 의해 반환되지만 질문 용도로는 로컬로 선언하고 있습니다. 내가 제대로 이해하면
$(document).ready(function() {
var data = '{"success": "0","patient_cid": "0"}';
var response = jQuery.parseJSON(data);
if (response.success == 0) {
if (response.patient_cid == 0) {
$('#resultpanel').html('<p>ID not found</p>');
}
if (response.patient_ambassador == 0) {
$('#resultpanel').html('<p>ID found but not an ambassador</p>');
}
if (response.soap_error == '1') {
$('#resultpanel').html('<p>SOAP error</p>').fadeIn('slow');
}
}
if (response.success == 1){
$('#resultpanel').html('<p>success</p>').fadeIn('slow');
}
else {
$('#resultpanel').html('<p>Error</p>').fadeIn('slow');
}
});
하나의 sidenote : 'success' 코드를 실제로 문자열로 래핑해야합니까? 그것은 단지 "성공"이어야하지 않습니까 : 0'? – jgauffin