동기적 프로그램 실행이 필요할때..
function doTheThing() {
return new Promise((resolve, reject) => {
$.ajax({
url: window.location.href,
type: 'POST',
data: {
key: 'value',
},
success: function (data) {
resolve(data) // ajax 이후 실행
},
error: function (error) {
reject(error)
},
}) // and ajax
})
}
doTheThing()
.then((data) => {
// ajax 이후 실행
console.log(data)
doSomethingElse()
})
.catch((error) => {
console.log(error)
})
출처 https://www.taniarascia.com/how-to-promisify-an-ajax-call/
'Javascript & jQuqery' 카테고리의 다른 글
Javascript) ajax 이후 특정 부분만 새로고침!! (0) | 2022.04.27 |
---|---|
JavaScript) highlight.js 사용하여 코드구문 강조 시키기 (0) | 2022.01.09 |
javaScript) jqgrid 명령어 (0) | 2021.07.20 |
javaScript) jqgrid 스크롤위치 가져오기 (0) | 2021.07.14 |
javaScript) jqgrid reloadGrid(리로드)후 특정 셀 클릭하기 (0) | 2021.07.13 |
댓글