我使用javascript进行祈祷。
window.onload=function()
{
jadwal_sholat = function()
{
geo = [1.03000000, 103.92000000, 3.07];
timezone = +7;
prayTimes.tune( {imsak: 2, subuh: 2, dhuhur: 2, ashar: 2, maghrib: 2, isya: 2} );
var date = new Date(); // today
prayTimes.setMethod('Depag');
var times = prayTimes.getTimes(date, geo, timezone);
var list = ["Imsak", "Subuh", "Dhuhur", "Ashar", "Maghrib", "Isya"];
var thisday=date.getDay();
var thismonth=date.getMonth();
var thisdate=date.getDate();
var thisyear=date.getFullYear();
var thisminute = date.getMinutes();
thisminute = ("0" + thisminute).slice(-2);
var thishour = date.getHours();
thishour = ("0" + thishour).slice(-2);
var thisseconds = date.getSeconds();
thisseconds = ("0" + thisseconds).slice(-2);
var months = new Array("Jan", "Feb", "Mar", "Apr", "Mei", "Jun", "Jul", "Agu", "Sep", "Okt", "Nov", "Des");
var name_of_days = new Array("Minggu", "Senin", "Selasa", "Rabu", "Kamis", "Jum"+"'"+"at", "Sabtu");
var day_name = name_of_days[thisday];
var monthname = months[thismonth];
var tanggal = thishour+': '+ thisminute+': ' +thisseconds+', '+day_name+", "+thisdate+" "+monthname+" "+thisyear;
var currentTimeF = thishour+':'+ thisminute;
var html = '<table>';
for(var i in list)
{
html += '<td class="box '+ list[i]+'">'+ list[i]+'<div class="timeValue">'+ times[list[i].toLowerCase()]+'</div></td>';
if(currentTimeF+":00" == times[list[i].toLowerCase()]+":00")
{
}
}
html += '</table>';
document.getElementById('todayPrayTime').innerHTML = html;
dateNow = day_name+", "+thisdate+" "+monthname+" "+thisyear;
currentTime = thishour+':'+ thisminute+':'+thisseconds;
document.getElementById('date').innerHTML = dateNow;
document.getElementById('time').innerHTML = currentTime;
}
show = function() {
jadwal_sholat();
}
show();
loadTime = function(){
jadwal_sholat();
setTimeout(loadTime, 1)
}
loadTime();
}
该功能运行正常。
但现在我想从数据库中获取一些价值。
geo和timezone&lt; - 将从数据库获取。
我不想刷新页面,所以可能会使用ajax自动刷新?
我的想法是:
$.ajax(
{
url: "chkValue",
type: "POST",
data:
{
mosqueeID: ID
},
dataType: "JSON",
success: function (jsonStr)
{
var timezone = jsonStr.timezone;
}
});
怎么做?有可能吗?
答案 0 :(得分:2)
function loadAjax(){
$.ajax(
{
url: "chkValue",
type: "POST",
data:
{
mosqueeID: ID
},
dataType: "JSON",
success: function (jsonStr)
{
//return this timezone or use this outside of the function with global scope
var timezone = jsonStr.timezone;
}
});
}
//reload every 1 second
setInterval(loadAjax(), 1000);
&#13;
尝试一下,让我知道它是否无效。您可能必须在ajax请求的success
中包含所有功能