JSON 객체처럼 보이지만 파싱 할 때 공백이 아닌 오류가 발생합니다. 구문 분석하지 않으면 요소에 액세스 할 수 없습니다. . 기본적으로 JSON의 각 요소에 액세스하여 표시하려고합니다. 여기 코드는 다음과 같습니다 (코드 내 반환 JSON (또는 무엇을jQuery AJAX 호출에서 JSON을 파싱합니다.
$('#cardText').change(function(){
if($('#cardText').val().trim().length == 9)
{
$.ajax({
url: 'components/Person.cfc',
//GET method is used
type: "POST",
//pass the data
data: {
method: "getGroup",
uid: $('#cardText').val(),
},
success: function(response) {
//obj = jQuery.parseJSON(response); -- I get a non-whitespace error if I do this
var Col1 = response.COLUMNS[0]; -- this gives me response.Columns is undefined
$('#form_result').html(response);
},
error: function(jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].');
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.\n' + jqXHR.responseText);
}
}
});
}
});
데이터 반환) JSON 것으로 보인다 이하 :
메모장에서{
"COLUMNS": ["PLAN", "NAME", "ID", "ISSUE", "TYPE", "LASTUSED", "BALANCE"],
"DATA": [["DINING STAFF CAFE 1919 ", "YOUNG, MARIA ", 8.03976343E8, "2001-04-02", 2.0, "2012-01-27", 1]]
}
는 (데이터 제한) { "열" [ "PLAN", "NAME"], "DATA": [[DINING STAFF CAFE 1919], [YOUNG, MARIA]]}
제한된 양의 값이 있지만 구문 분석을 시도 할 때 여전히 흰색이 아닌 오류가 발생합니다. 이것은 파싱없이 직접 div에 대한 응답을 호출합니다. { "열", "이름", "데이터": [[스태프 카페 1919 ","젊은, 마리아]]]} – user1371409