[Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.
오류기록 2018. 3. 5. 15:07
1. 현상
ajax 사용 중 Chrome Console에 다음 경고 문구 발생
[Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
2. 발생 코드
$.ajax({ url : getContextPath()+"/test", type : "POST", async : false , // **이 부분 때문에 발생함** success : function(data){ gridOptions.api.setRowData(data); }, error: function(){ alert("error"); } });
3. 발생 원인
결론부터 말하면 ajax를 동기식으로 처리하게 될 경우 사용자의 경험에 안좋은 영향을 끼치기 때문에 사용을 하지 말라는 것입니다.
ajax는 말그대로 비동기 방식이기 때문에 호출 순서를 보장하지 않아 async : false 옵션을 통해 ajax가 종료 후 함수가 종료되도록 할 수 있습니다.
하지만 이 옵션을 주게 되면, ajax가 종료될때까지 함수가 종료되지 않으므로 사용자의 성능에 안좋은 영향을 준다는 소리인 듯합니다.
( jquery ajax의 async 기본값은 true)
4. 해결 방법
경고(Deprecation)이기 때문에 기능상 문제는 없습니다.
아직은 이 부분을 없애기 위해 ajax를 async: true를 통해 비동기식으로 처리하면서
기능상 오류가 없도록 소스를 구성하는 방법밖에 모르겠습니다.