ajax.blade.php
1.9 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
var nextUrl=$("#url").val();
function errorMsg(pesan){
$(".pesan").html('<div class="alert alert-danger" role="alert"><i class="fa fa-ban"></i> Terjadi kesalahan. Error '+ pesan +'</div>');
$("input").prop('disabled', false);
$(".loading").hide();
$(".modal-footer").show();
}
function successMsg(data){
if(data.status == true){
if (typeof data.url !== 'undefined') {
location.href= data.url;
} else {
$('#datatable').DataTable().ajax.reload();
$('.modal').modal('hide');
Swal.fire({
title: 'Okay...',
text: 'Berhasil proses data',
type: 'success',
timer: 1500
});
}
}else{
$("button").prop("disabled", false);
$("input").prop('disabled', false);
$.each(data.pesan, function(i, item) {
$('#'+i).closest('.form-group').addClass('has-error');
$('#'+i).focus();
$(".pesan").html('<div class="alert alert-danger" role="alert"><i class="fa fa-ban"></i> '+ item +'</div>');
return false;
});
}
$(".loading").hide();
{{-- $(".pesan").html(''); --}}
$(".modal-footer").show();
}
function sebelumKirim(){
$(".pesan").html('<div class="alert alert-info" role="alert"><center><i class="fa fa-spinner fa-spin"></i> Loading...</center></div>');
$("input").prop('disabled', true);
$(".loading").show();
$(".modal-footer").hide();
}
function goAjax(targetUrl, dataString, methodType = 'POST'){
$.ajax({
type: methodType,
url: targetUrl,
data: dataString,
enctype: 'multipart/form-data',
dataType: 'json',
cache: false,
beforeSend: function(){
sebelumKirim();
},
success: function(data){
successMsg(data);
},
error: function(x, e){
// errorMsg(x.status);
}
});
}
function addCommas(nStr)
{
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
return x1 + x2;
}