JQuery
[JQuery] json 데이터 파일 읽기 ajax, getJSON / $.ajax(), $.getJSON()
chsr
2021. 4. 28. 09:36
728x90
반응형
■ JQuery json 데이터 파일 읽기 ajax, getJSON 차이 / $.ajax(), $.getJSON
■ 사용법
- $.getJSON()
* getJSON 사용 시 일부 옵션을 활용할 수 없음 (async, type 옵션 불가)
$.getJSON("${path}/filepath.php", {"value" : "tmpVal"}, function(data, textStatus) {
console.log(data);
});
- $.ajax()
* ajax 옵션 async - ajax 통신의 동기/비동기 여부에 대한 옵션 (default값은 true)
async : false 의 경우 ajax call을 동기로 처리하여 요청에 대한 응답이 있을 때까지 모든 처리가 중단되며, beforeSend 부분이 작동되지 않을 수 있으니 참고바람
$.ajax({
method: 'POST',
url: "${path}/filepath.php",
data: {
value : "tmpVal"
},
dataType: "json",
timeout : 5000, // Response wait time (1000 = 1seconds)
type: "POST",
async: false,
beforeSend : function(request){
// Performed before calling Ajax
showLoading();
},
success: function (data) {
// Do when ajax call success
console.log(data);
},
error: function() {
// Do when ajax call fail
},
complete: function() {
// Run after running Ajax
hideLoading();
}
});
728x90
반응형