2016-03-15 176 views
0

我想讓表列可編輯,但我不是很熟悉JS,所以有人可以給我看光嗎? 要保存文件,我找到了一個很棒的jquery插件。 但對於編輯和保存我沒有找到一個方法來做到這一點...做一個表列可編輯並保存在一個文件

$(document).ready(function() { 
    /* Init DataTable */ 
    var table2Edit = $('#table2Edit').dataTable(); 

    // Save table in json file 
    var table = $('#table2Edit').tableToJSON();   
    $.ajax({ 
     type : "POST", 
     url : "ajax.php", 
     dataType : 'json', 
     data : { 
      json : JSON.stringify(table) /* convert here only */ 
     } 
    }); 
}); 

服務器端:

$json = $_POST['json']; 
      if (json_decode($json) != null) { /* sanity check */ 
       $file = fopen('myTable.json','w+'); 
       fwrite($file, $json); 
       fclose($file); 
       var_dump($file); 
    } 

回答

相關問題