themouette / jquery-week-calendar

A weekly calendar plugin based on jquery and jquery-ui
http://groups.google.com/group/jquery-week-calendar
720 stars 253 forks source link

IE8 Remote data #174

Closed zeitnot closed 11 years ago

zeitnot commented 11 years ago

Hi,

I create an ajax query to fetch events dnynamically. When events run as statically there is no problem but when I am trying to fetch events, IE8 does not parse json output. With chrome or firefox there is no any problem. It works like charm. My ajax call is as below:

        var call= $.ajax({
          "url" :"/new_program/front_calendar_controller.php",
          "data" : "action=list&start_date="+start.toISOString()+"&end_date="+end.toISOString(),
          "async" : false,
          "type" : "post",
          "dataType" : "json",
          "success": function(msg){                
          }
      });

      //console.log(JSON.parse(call.responseText));
      //return;
      $response = JSON.parse(call.responseText);

      events = [];
      for (i in $response){

          msg = $response;
          val = [];

          s_date = new Date(Date.createFromMysql(msg[i].StartDate));
          e_date = new Date(Date.createFromMysql(msg[i].EndDate));
          val.id = msg[i].Id;
          val.teacher = msg[i].Teacher;
          val.content = msg[i].Content;
          val.start = new Date(s_date);
          val.end = new Date(e_date);
          val.bg_color = msg[i].BgColor;
          val.readOnly = true;
          events.push(val);

      }

     callback(getEventData(events));

It seems that it crashes because of datetime. Dates are coming as mysql datetime format from my server. To convert them I create a function as below:

    Date.createFromMysql = function(mysql_string)
    { 
       if(typeof mysql_string === 'string')
       {
          var t = mysql_string.split(/[- :]/);

          //when t[3], t[4] and t[5] are missing they defaults to zero
          return new Date(t[0], t[1] - 1, t[2], t[3] || 0, t[4] || 0, t[5] || 0);          
       }

       return null;   
    }

Is this a bug or what is the correct way to parse dynamic json usin IE8/9/10?

zeitnot commented 11 years ago

toISOString() function generates quotes when rendered with ie8 js engine. So update the code:

    var call= $.ajax({
      "url" :"/new_program/front_calendar_controller.php",
      "data" : "action=list&start_date="+start.toISOString().replace(/["']/g, "")+"&end_date="+end.toISOString().replace(/["']/g, ""),
      "async" : false,
      "type" : "post",
      "dataType" : "json",
      "success": function(msg){                
      }
  });  

Now it is workinG with İE8.