Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- VAR
- createElement
- input
- 학습법 #집중력
- boolean
- FOR
- htmlFor
- Append
- Openlayers
- const
- appendChild
- Let
- createtextnode
Archives
- Today
- Total
Atomic Habits
Promise Simple Code 본문
https://www.codegrepper.com/code-examples/javascript/jquery+ajax+promise
“jquery ajax promise” Code Answer’s
function doTheThing() {
return new Promise((resolve, reject) => {
$.ajax({
url: window.location.href,
type: 'POST',
data: {
key: 'value',
},
success: function (data) {
resolve(data)
},
error: function (error) {
reject(error)
},
})
})
}
doTheThing()
.then((data) => {
console.log(data)
doSomethingElse()
})
.catch((error) => {
console.log(error)
})
function ajax(options) {
return new Promise(function (resolve, reject) {
$.ajax(options).done(resolve).fail(reject);
});
}
function doTheThing() {
$.ajax({
url: window.location.href,
type: 'POST',
data: {
key: 'value',
},
success: function (data) {
console.log(data)
},
error: function (error) {
console.log(error)
},
})
}
doTheThing()
doSomethingElse()
'IT > JavaScript-JQuery' 카테고리의 다른 글
return { a, b}; -> f.a | return [a, b]; -> f[0] (0) | 2022.07.07 |
---|---|
TDZ -> ReferenceError: Cannot access 'white' before initialization (0) | 2022.07.07 |
[javascript] Promise 가 뭔가요? (0) | 2022.07.07 |
동기식 (Synchronous) / 비동기식 (Asynchronous) (0) | 2022.07.07 |
jQuery: data() 이해와 활용 (0) | 2022.07.06 |
Comments