https://lee-mandu.tistory.com/437
jquery promise 사용하기
안녕하세요. 너무 현실에 안주하였다는 사실을 깨달았습니다. promise를 듣고 너무 생소하여 찾아봤더니.. 현재 상당히 많이 사용하고 있어 더욱더 놀랬습니다. promise와 관련된 더욱 깊이있는 개
lee-mandu.tistory.com
<span style="font-size: 12pt;">function promise_function(){
return new Promise(function(resolve, reject){
$.ajax({
url: '/sm/util/ajaxTest',
data: 'num=10',
type: 'post',
dataType: 'json',
success : function(result){
var num = result.num;
resolve(num);
}
});
});
}
function firstAjax(num){
return new Promise(function(resolve, reject){
alert('첫번째 실행');
$.ajax({
url: '/sm/util/ajaxTest',
data: 'num=20',
type: 'post',
dataType: 'json',
success : function(result){
var num = result.num;
resolve(num);
}
});
});
}
function secondAjax(num){
return new Promise(function(resolve, reject){
alert('두번째 실행');
$.ajax({
url: '/sm/util/ajaxTest',
data: 'num=20',
type: 'post',
dataType: 'json',
success : function(result){
var num = result.num;
resolve();
}
});
});
}
function successFunction(){
alert('성공');
return false;
}
function errorFunction(){
alert('에러');
return false;
}
promise_function()
.then(firstAjax)
.then(secondAjax)
.then(successFunction)
.catch(errorFunction);
</span>
출처: https://lee-mandu.tistory.com/437 [개발/일상_Mr.lee]
출처: https://lee-mandu.tistory.com/437 [개발/일상_Mr.lee]
출처: https://lee-mandu.tistory.com/437 [개발/일상_Mr.lee]
댓글