javascript - select day and special date load by ajax to set in gldatepicker -
i using gldatepicker.i want load settings database ajax gldatepicker such day of week,special date etc.now have following js code this:
$(document).ready(function () { loadallsettings(); }); var loadallsettings = function () { startdate = ''; enddate = ''; selectday = ''; offdays = ''; $.ajax({ url: "bs_client_function.php", type: "post", datatype: "json", data: { action: 'getdaterange' }, success: function (html) { // alert(html.start); startdate = date.parse(html.start); enddate = date.parse(html.end); } }); $.ajax({ url: "bs_client_function.php", type: "post", datatype: "json", data: { action: 'getoffdays' }, success: function (html) { = 0; offdays = '['; while (i < html.length) { offdays = offdays + { date: new date(html[i]), repeatyear: false, cssclass: 'noday' }; = + 1; } offdays = offdays + ']'; } }); $.ajax({ url: "bs_client_function.php", type: "post", data: { action: 'getdays' }, success: function (html) { var data = $.parsejson(html); // alert("[" + data + "]"); selectday = '[' + data + ']'; // alert(selectday); showcalender(startdate, enddate, selectday, offdays); } }); alert(selectday); console.log('selectday' + selectday); };
i have checked data correctlly formated gldatepicker recommanded.in show calender function:
var showcalender = function (startdate, enddate, selectday, offdays) { var dd = $('#mydate').gldatepicker({ showalways: true, allowmonthselect: true, allowyearselect: false, prevarrow: '\u25c4', nextarrow: '\u25ba', cssname: 'darkneon', selectabledow: selectday, dowoffset: 0, selecteddate: new date(), selectabledaterange: [{ from: new date(startdate), to: new date(enddate) }, ], specialdates: offdays }); };
now stardate , enddate rightly working.selectday,offdays not working. print selectday in console got this: [1,2,3] not woking.what missing or should right way it. thanks in advance...
the problem how getting data fill gldatepicker. have 3 ajax calls, these calls default asynchronous, execute showcalender function in last success function, have no sureness preceding calls completed.
you can make ajax calls synchronous setting async
parameter false
see jquery docs:
async (default: true) type: boolean default, requests sent asynchronously (i.e. set true default). if need synchronous requests, set option false. cross-domain requests , datatype: "jsonp" requests not support synchronous operation. note synchronous requests may temporarily lock browser, disabling actions while request active. of jquery 1.8, use of async: false jqxhr ($.deferred) deprecated; must use success/error/complete callback options instead of corresponding methods of jqxhr object such jqxhr.done() or deprecated jqxhr.success().
or can chain them in every success callbacks, code difficult mantain or can use plugin manager multiple ajax calls http://docs.jquery.com/ajaxqueue
it works local data, see: http://jsfiddle.net/irvindominin/v59e7/
pay attention @ object specialdates
option needs:
specialdates: [{ date: new date(0, 8, 5), data: { message: 'happy birthday!' }, repeatyear: true, cssclass: 'special-bday' }, { date: new date(2013, 0, 8), data: { message: 'meeting every day 8 of month' }, repeatmonth: true }]
Comments
Post a Comment