title: POST data using AJAX in Codeigniter calendar function with JQUERY UI features
body: <p>The code below is a Codeigniter Event Calendar feature from <a href="http://net.tutsplus.com/tutorials/php/codeigniter-from-scratch-the-calendar-library" rel="nofollow">here</a>.</p>
  
  <p>The calendar is click-able and you can enter data into the date field through a 'prompt' box. The data is then shown on the calendar date field. </p>
  
  <p>However I am trying to use a JQUERY 'dialog' box with a 'spinner' as the input field rather than a 'prompt' box. </p>
  
  <p>All the codes below are working perfectly accept for the JQUERY section at the end when I am trying use AJAX to POST the data. Codeigniter is unable to detect the POST data from the dialog box.</p>
  
  <p>Could anyone please help? </p>
  
  <pre><code>     //CONTROLLER
  
      class Mycal extends CI_Controller {
  
      public function index() {
         $this-&gt;display();
      }
  
      function display($year = null, $month = null){
  
      if (!$year) {
          $year = date('Y');
      }
      if (!$month) {
          $month = date('m');
      }
  
      $this-&gt;load-&gt;model('Mycal_model');
  
      if($day = $this-&gt;input-&gt;post('day')){
          $this-&gt;Mycal_model-&gt;add_calendar_data(
              "$year-$month-$day",
              $this-&gt;input-&gt;post('data')
          );
      }
  
      $data['calendar'] = $this-&gt;Mycal_model-&gt;generate($year, $month);
  
      $this-&gt;load-&gt;view('mycal_view', $data); 
  }
  
  }
  
      //MODEL
  
      class Mycal_model extends CI_Model{
  
      function get_calendar_data($year, $month){
  
      $query = $this-&gt;db-&gt;select('date, data')-&gt;from('calendar')
          -&gt;like('date', "$year-$month", 'after')-&gt;get();
  
      $cal_data = array();
  
      foreach ($query-&gt;result() as $row){
          $cal_data[substr($row-&gt;date,8,2)] = $row-&gt;data;
      }
  
      return $cal_data;
  }
  
  function add_calendar_data($date, $data){
  
      if($this-&gt;db-&gt;select('date')-&gt;from('calendar')
          -&gt;where('date', $date)-&gt;count_all_results()) {
  
          $this-&gt;db-&gt;where('date', $date)-&gt;update('calendar', array(
              'date'=&gt;$date,
              'data'=&gt;$data
          ));
  
      }else{
  
          $this-&gt;db-&gt;insert('calendar', array(
              'date'=&gt;$date,
              'data'=&gt;$data
          ));
      }
  }
  
  function generate ($year, $month){
  
      $this-&gt;load-&gt;library('calendar', $this-&gt;conf);
      $cal_data = $this-&gt;get_calendar_data($year, $month);    
      return $this-&gt;calendar-&gt;generate($year, $month, $cal_data)      
  }
  
  
      //VIEW
  
      &lt;?php echo $calendar; ?&gt;
  
      &lt;div id="dialog-form" title="Select number of items"&gt;
  
      &lt;p&gt;
          &lt;label for="spinner"&gt;Number of items:&lt;/label&gt;
          &lt;input id="spinner" name="spinner" value="0" /&gt;
      &lt;/p&gt;
  
      &lt;/div&gt;
  
      //JQUERY
  
      &lt;script type="text/javascript"&gt;
  
  $(document).ready(function() {
  
      $(function() {
          $( "#spinner" ).spinner({
              min: 0,
              max: 10,
              step: 1,
          });
      });
  
      $('.calendar .day').click(function() {
          $('#dialog-form').dialog("open");
      }); 
  
      $(function() {  
          $('#dialog-form')
              .attr('title', 'Number of items')
              .dialog({ 
                  autoOpen: false,
                  buttons: { 
                      'Ok': function() {
                          day_num = $(this).find('.day_num').html();
                          day_data = $("#spinner").val();
  
  
                              $.ajax({
                                  url: window.location,
                                  type: 'POST',
                                  data: {
                                      day: day_num,
                                      data: day_data
                                  },
                                  success: function(msg){
                                      location.reload();
                                  }
                              })      
                      },
  
                  },
  
              });
  
      });
  }); 
  &lt;/script&gt;
  </code></pre>