【问题标题】:Cannot save data to a cell using autosave with handsontable无法将数据保存到单元格中使用自动保存和handsontable
【发布时间】:2012-11-01 14:17:57
【问题描述】:

我在使用 hansontable 从单元格保存数据时遇到了一些问题,我可以使用一些建议。

问题是:

  1. 自动保存 1 个单元格发送未定义。
  2. 自动保存多个单元格也未定义。
  3. 点击保存按钮后,控制台显示:Save error. POST method is not allowed on GitHub Pages. Run this example on your own server to see the success message

代码:

<script>
          var $container = $("#excel");
          var $console = $("#excelconsole");
          var $parent = $container.parent();
          var autosaveNotification;
          $container.handsontable({
            startRows: 1,
            startCols: <?=$num_rName+1?>,//count room type name from db
            rowHeaders: true,
            //colHeaders: ['Date/Room Types', 'Year', 'Price'],
            colHeaders: <?echo json_encode($_array);?>,
            minSpareCols: 0,
            minSpareRows: 1,
            contextMenu: true,
            onChange: function (change, source) {
              if (source === 'loadData') {
                return; //don't save this change
              }
              if ($parent.find('input[name=autosave]').is(':checked')) {
                clearTimeout(autosaveNotification);
                $.ajax({
                  url: "inc/excel_save.php",
                  dataType: 'json',
                  type: "POST",
                  data: change, //contains changed cells' data
                  complete: function (data) {
                    $console.text('Autosaved (' + change.length + ' cell' + (change.length > 1 ? 's' : '') + ')');
                    autosaveNotification = setTimeout(function () {
                      $console.text('Changes will be autosaved');
                    }, 1000);
                  }
                });
              }
            }
          });
          var handsontable = $container.data('handsontable');

          $parent.find('button[name=load]').click(function () {
            $.ajax({
              url: "inc/excel_load.php",
              dataType: 'json',
              type: 'GET',
              success: function (res) {
                handsontable.loadData(res.data);
                $console.text('Data loaded');
              }
            });
          });

           $parent.find('button[name=save]').click(function () {
            $.ajax({
              url: "inc/excel_save.php",
              data: {"data": $("#excel").handsontable('getData')}, 
              dataType: 'json',
              type: 'POST',
              success: function (res) {
                if (res.result === 'ok') {
                  $console.text('Data saved');
                }
                else {
                  $console.text('Save error');
                }
              },
              error: function () {
                $console.text('Save error. POST method is not allowed on GitHub Pages. Run this example on your own server to see the success message.');
              }
            });
          });

          $parent.find('input[name=autosave]').click(function () {
            if ($(this).is(':checked')) {
              $console.text('Changes will be autosaved');
            }
            else {
              $console.text('Changes will not be autosaved');
            }
          });
        </script>

excel_save.php

<?
foreach($_POST as $key=>$val){//test the var passed
    echo "$key=$val<br />";
}
?>

数据已加载

使用未定义保存

【问题讨论】:

    标签: jquery save undefined handsontable


    【解决方案1】:

    改变

    data: change,

    data : {changes: change},

    找到它here

    【讨论】:

      猜你喜欢
      • 2013-08-11
      • 2017-05-10
      • 2015-07-14
      • 2013-04-24
      • 2015-04-23
      • 2014-02-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-29
      相关资源
      最近更新 更多