From 9b890e643eb809556011aea02abf696b2856c387 Mon Sep 17 00:00:00 2001 From: Diki Siswanto Date: Fri, 24 Apr 2020 16:03:00 +0800 Subject: [PATCH] hot-fix: add error when internet disconnect or when something wrong --- assets/js/widget.js | 69 +++++++++++++++++++++++---------------- assets/js/widget.min.js | 2 +- widgets/jadwal_shalat.php | 2 +- 3 files changed, 43 insertions(+), 30 deletions(-) diff --git a/assets/js/widget.js b/assets/js/widget.js index f42cefc..e906609 100644 --- a/assets/js/widget.js +++ b/assets/js/widget.js @@ -1,36 +1,49 @@ $(document).ready(function () { if ($('#jadwal-shalat').length) { - + const BASE_API_URL = 'https://api.banghasan.com/'; const endpoint_nama_kota = `sholat/format/json/kota/kode/${KODE_KOTA}`; const endpoint_jadwal = `sholat/format/json/jadwal/kota/${KODE_KOTA}/tanggal/${TANGGAL}`; - // get nama kota - $.ajax({ - url: BASE_API_URL + endpoint_nama_kota, - type: 'get', - dataType: 'json', - crossDomain: true, - success: function (res) { - $('[data-name=kota]').html(res.kota[0].nama).removeClass('shimmer line-short'); - } - }); - - // get jadwal sholat - $.ajax({ - url: BASE_API_URL + endpoint_jadwal, - type: 'get', - dataType: 'json', - crossDomain: true, - success: function (res) { - $('.shimmer').removeClass('shimmer'); - $('[data-name=imsak]').html(`Imsak${res.jadwal.data.imsak}`); - $('[data-name=subuh]').html(`Subuh${res.jadwal.data.subuh}`); - $('[data-name=dzuhur]').html(`Dzuhur${res.jadwal.data.dzuhur}`); - $('[data-name=ashar]').html(`Ashar${res.jadwal.data.ashar}`); - $('[data-name=maghrib]').html(`Maghrib${res.jadwal.data.maghrib}`); - $('[data-name=isya]').html(`Isya${res.jadwal.data.isya}`); - } - }) + try { + // get nama kota + $.ajax({ + url: BASE_API_URL + endpoint_nama_kota, + type: 'get', + dataType: 'json', + crossDomain: true, + success: function (res) { + $('[data-name=kota]').html(res.kota[0].nama).removeClass('shimmer line-short'); + }, + error: function (err) { + $('.line-short').html(` Gagal memuat`); + $('.line-short').removeClass('shimmer line-short'); + } + }); + + // get jadwal sholat + $.ajax({ + url: BASE_API_URL + endpoint_jadwal, + type: 'get', + dataType: 'json', + crossDomain: true, + success: function (res) { + $('.shimmer').removeClass('shimmer'); + $('[data-name=imsak]').html(`Imsak${res.jadwal.data.imsak}`); + $('[data-name=subuh]').html(`Subuh${res.jadwal.data.subuh}`); + $('[data-name=dzuhur]').html(`Dzuhur${res.jadwal.data.dzuhur}`); + $('[data-name=ashar]').html(`Ashar${res.jadwal.data.ashar}`); + $('[data-name=maghrib]').html(`Maghrib${res.jadwal.data.maghrib}`); + $('[data-name=isya]').html(`Isya${res.jadwal.data.isya}`); + }, + error: function (err) { + $('.box-shalat').html(` Gagal memuat`); + $('.box-shalat').removeClass('shimmer'); + } + }); + } catch(err) { + console.log(err); + } + } }) \ No newline at end of file diff --git a/assets/js/widget.min.js b/assets/js/widget.min.js index f4f6c5c..0f6c818 100644 --- a/assets/js/widget.min.js +++ b/assets/js/widget.min.js @@ -1 +1 @@ -$(document).ready(function(){if($("#jadwal-shalat").length){const a="https://api.banghasan.com/",s=`sholat/format/json/kota/kode/${KODE_KOTA}`,t=`sholat/format/json/jadwal/kota/${KODE_KOTA}/tanggal/${TANGGAL}`;$.ajax({url:a+s,type:"get",dataType:"json",crossDomain:!0,success:function(a){$("[data-name=kota]").html(a.kota[0].nama).removeClass("shimmer line-short")}}),$.ajax({url:a+t,type:"get",dataType:"json",crossDomain:!0,success:function(a){$(".shimmer").removeClass("shimmer"),$("[data-name=imsak]").html(`Imsak${a.jadwal.data.imsak}`),$("[data-name=subuh]").html(`Subuh${a.jadwal.data.subuh}`),$("[data-name=dzuhur]").html(`Dzuhur${a.jadwal.data.dzuhur}`),$("[data-name=ashar]").html(`Ashar${a.jadwal.data.ashar}`),$("[data-name=maghrib]").html(`Maghrib${a.jadwal.data.maghrib}`),$("[data-name=isya]").html(`Isya${a.jadwal.data.isya}`)}})}}); \ No newline at end of file +$(document).ready(function(){if($("#jadwal-shalat").length){const a="https://api.banghasan.com/",s=`sholat/format/json/kota/kode/${KODE_KOTA}`,l=`sholat/format/json/jadwal/kota/${KODE_KOTA}/tanggal/${TANGGAL}`;try{$.ajax({url:a+s,type:"get",dataType:"json",crossDomain:!0,success:function(a){$("[data-name=kota]").html(a.kota[0].nama).removeClass("shimmer line-short")},error:function(a){$(".line-short").html(' Gagal memuat'),$(".line-short").removeClass("shimmer line-short")}}),$.ajax({url:a+l,type:"get",dataType:"json",crossDomain:!0,success:function(a){$(".shimmer").removeClass("shimmer"),$("[data-name=imsak]").html(`Imsak${a.jadwal.data.imsak}`),$("[data-name=subuh]").html(`Subuh${a.jadwal.data.subuh}`),$("[data-name=dzuhur]").html(`Dzuhur${a.jadwal.data.dzuhur}`),$("[data-name=ashar]").html(`Ashar${a.jadwal.data.ashar}`),$("[data-name=maghrib]").html(`Maghrib${a.jadwal.data.maghrib}`),$("[data-name=isya]").html(`Isya${a.jadwal.data.isya}`)},error:function(a){$(".box-shalat").html(' Gagal memuat'),$(".box-shalat").removeClass("shimmer")}})}catch(a){console.log(a)}}}); \ No newline at end of file diff --git a/widgets/jadwal_shalat.php b/widgets/jadwal_shalat.php index fd337ac..36b1d15 100644 --- a/widgets/jadwal_shalat.php +++ b/widgets/jadwal_shalat.php @@ -6,7 +6,7 @@ const KODE_KOTA = ""; const TANGGAL = ""; - +