javascript - 如何使用jquery-tabledit通过javascript将变量传递给ajax?

标签 javascript php jquery html ajax

我目前正在使用jquery插件Tabledit当我使用内联编辑(如示例 3 所示)时,它会调用我的 php 页面。我不知道如何将编辑中所做的更改传递到新的 php 页面,以便我可以在数据库中更改它。当你按回车键时它会改变。 (我猜测输入后它会调用 edittask.php)

html 这里是表格的一部分。输入新文本后按 Enter 键它会发生变化。

<td class="tabledit-view-mode"> <span class=" tabledit-span ">header text</span>
    <input class="tabledit-input form-control input-sm" type="text" name="description" value=" " style="display: none;" disabled="" />
</td>

javascript

$('#thetable').Tabledit({
    url: 'editTask.php',
    editButton: false,
    deleteButton: false,
    columns: {
        identifier: [0, 'id'],
        editable: [
            [1, 'Header'],
            [2, 'Description']
        ]
    }
});

最佳答案

根据这个sample ,在您的 php 脚本中您可以使用 POST 数组中的变量。在您的情况下:$_POST['description']$_POST['header']

我的意思是:

index.php:

<table class="table table-striped table-bordered" id="example3">
<thead>
    <tr>
        <th>#</th>
        <th>Header</th>
        <th>Description</th>
    </tr>
</thead>
<tbody>
    <tr>
        <td>1</td>
        <td>Header 1</td>
        <td>Description 1</td>
    </tr>
</tbody>
</table>
<script>
    $(function(){
        $('#example3').Tabledit({
            url: 'example.php',
            editButton: false,
            deleteButton: false,
            hideIdentifier: true,
            columns: {
                identifier: [0, 'id'],
                editable: [[1, 'header'], [2, 'description']]
            }
        });
    });
</script>

示例.php:

print_r($_POST); 
// Array ( [id] => 1 [header] => Header 123 [action] => edit )
// Implement your logic here...

关于javascript - 如何使用jquery-tabledit通过javascript将变量传递给ajax?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31811135/

相关文章:

javascript - 在 http.get() 之后将结果保存在 Angular 4 的数组中

javascript - 如何使用 if 函数在我的 Web 网格中隐藏一个复选框?

javascript - 无法在 HTML5、jquery 中验证跨度单选按钮

php - ffmpeg-php - avi 到 flv,视频长度和音频

jquery - 将 div 移动到其他父级,因此它继承自该父级

javascript - 在 javascript 中加载页面而不打开它

javascript - 使 ExtJS 4 网格内容可选择

javascript - 初学者在javascript中异步值传递和返回

php - MySQL 额外列信息

php - 在 PDF 中插入换行符