- 정보공유
[JQUERY] ajax 를 이용한 비동기식 삭제 데이터 처리.
javascript
function confirm_action(action, msg) {
if (confirm(msg)) {
return $.ajax({
type : 'post',
async : false,
url : action,
dataType : 'json',
timeout : 30000,
cache : false ,
success : function(response, status, request) {
return response;
}
});
}
}
$(document).ready(function() {
$(document).on('click', '#delete', function (e) {
e.preventDefault();
var action = $(this).attr('href');
var req = confirm_action(action, "선택하신 정보를 삭제하시겠습니까?");
if (req.statusText == 'OK') {
var data = req.responseJSON;
if (data.rescd == '00') {
alert(data.restx);
location.reload();
}
else {
alert(data.restx);
}
}
});
});
html
<a href="./ajax.delete.php" id="delete">삭제</a>