본문 바로가기

카테고리 없음

json undefined 체크하기

$.ajax({
type : 'GET',
url:"https://domain.com",
dataType:"jsonp",
error : function(error) {
console.log("Error!");
},
success : function(data) {

var jsonData = JSON.stringify(data);
var json = JSON.parse(jsonData);

var json_check;
var json_msg;
if (json.routes !== undefined) {        // json undefined check
json_check = 1;
} else {
json_msg = json.error.error_message;
json_check = 2;
}

var jsonData1 = "";
var jsonData2 = "";

if(json_check == 1) {
// 정상

} else {
// 오류
}

},
complete : function() {
console.log("complete!");
}
});


// 이런식으로 사용하면 됨