IT TIP

console.log (result)는 [object Object]를 반환합니다.

itqueen 2020. 11. 4. 21:02
반응형

console.log (result)는 [object Object]를 반환합니다. result.name은 어떻게 얻나요?


이 질문에 이미 답변이 있습니다.

내 스크립트가 [object Object]결과 로 반환 됩니다 console.log(result).

사람이하는 방법을 설명시겠습니까 console.log반환 idname에서 result?

$.ajaxSetup({ traditional: true });

var uri = "";

$("#enginesOuputWaiter").show();    
$.ajax({
    type: "GET",
    url: uri,
    dataType: "jsonp",
    ContentType:'application/javascript',
    data :{'text' : article},
    error: function(result) {
        $("#enginesOuputWaiter").hide();
        if(result.statusText = 'success') {
            console.log("ok");
            console.log(result);
        } else {
            $("#enginesOuput").text('Invalid query.');
        }
    }
});

console.log(JSON.stringify(result))문자열 형식으로 JSON을 가져 오는 데 사용 합니다.

편집 : 당신의 의도가 결과 객체에서 id 및 기타 속성을 가져 오는 것이고 콘솔이 있는지 확인하고 싶다면 hasOwnProperty속성이 있는지 확인 하고 액세스 할 수 있습니다.

var obj = {id : "007", name : "James Bond"};
console.log(obj);                    // Object { id: "007", name: "James Bond" }
console.log(JSON.stringify(obj));    //{"id":"007","name":"James Bond"}
if (obj.hasOwnProperty("id")){
    console.log(obj.id);             //007
}

JSON.stringify(result)JS 개체를 JSON 문자열로 변환하기 위해 추가해보십시오 .

귀하의 코드 error에서 AJAX 요청이 실패하면 호출되는 결과를 로깅하고 있음을 알 수 있으므로 ID / 이름 / 등에 액세스하는 방법을 모르겠습니다. 그런 다음 (오류 조건 내에서 성공을 확인하고 있습니다!).

Chrome의 콘솔을 사용하는 경우 JSON을 문자열 화하지 않고도 객체를 탐색 할 수 있어야 디버깅이 쉬워집니다.

참고 URL : https://stackoverflow.com/questions/41336663/console-logresult-returns-object-object-how-do-i-get-result-name

반응형