javascript - Create dynamic list of dates in jQuery -
in javascript need plain list of dates (for jquery datepicker):
["16-5-2013", "24-5-2013", "25-5-2013", "26-5-2013"] because list dynamic want use ajax call:
var disableddays = $.ajax({ type: 'get', url: "/disabled-days", }); in django wrote test view returns data in json:
def disabled_days(request, soort): django.http import httpresponse import json soort = ["16-5-2013", "24-5-2013", "25-5-2013", "26-5-2013", "27-5-2013"] return httpresponse(json.dumps(soort), mimetype="application/json") is json here way pass data? find date list in responstext, unable access data.
for example tried iter on items like:
(i = 0; < disableddays1.length; i++) { item = results[i]; disableddays.push(item); } this results in empty list.
the responsetext (encoding json):
["16-5-2013", "24-5-2013", "25-5-2013", "26-5-2013"] when console.log() see info:
get http://localhost:8080/disabled-days 200 ok 39ms jquery-1.9.1.js (regel 8526) object { readystate=1, getresponseheader=function(), getallresponseheaders=function(), meer...} below solution anh tĂș gave (not working yet):
var disableddays1 = $.ajax({ type: 'get', url: "/disabled-days", }); var disableddays = [] (i = 0; < disableddays1.length; i++) { item = results[i]; if(typeof(responsetext)==string){responsetext= json.parse(responsetext);} $.each(responsetext,function(i,item){disableddays.push(item);}); } console.log(disableddays);
i think you're handling ajax request wrong. declare callback function when request success , process data received this:
var disableddays = [] $.ajax({ type: 'get', url: "/disabled-days", success: function(data){ // data response json disableddays = data // whatever needs done disableddays, // should array of dates. // process should inside method because of asynchronous // javascript method execution } }); hope helps!
Comments
Post a Comment