首页 > 解决方案 > 如何在 JQuery jtable 中配置 REST HTTP 方法

问题描述


我在 jQuery jtable 中找不到任何示例来为我的操作使用不同的 HTTP 方法。事实上,我的后端使用@GET 列出数据@POST 添加数据,@DELETE 删除数据,@PUT 更新数据。但是,似乎 jQuery 对所有操作都使用了 HTTP POST:

<script type="text/javascript">
    $(document).ready(function() {
        $('#StudentTableContainer').jtable({
            title : 'Students List',
            paging: false,
            actions: {
                listAction: 'http://localhost:8080/Controller/list',
                createAction:'http://localhost:8080/Controller/create',
                updateAction: 'http://localhost:8080/Controller/update',
                deleteAction: 'http://localhost:8080/Controller/delete'
            },
            fields : {
                id : {
                    title : 'id',
                    sort :true,
                    width : '30%',
                    key : true,
                    list : true,
                    edit : false,
                    create : true
                },
                name : {
                    title : 'Name',
                    width : '30%',
                    edit : true
                },
                department : {
                    title : 'Department',
                    width : '30%',
                    edit : true
                },
                emailId : {
                    title : 'Email',
                    width : '20%',
                    edit : true
                }
            }
        });
        $('#StudentTableContainer').jtable('load');
    });

知道如何为每个操作设置特定的 HTTP 方法吗?

标签: jqueryjquery-jtable

解决方案


当你给 jTable 一个 URL 作为一个动作时,它会使用标准的 jQuery ajax 来执行这个 URL。
但是,您可以改为提供延迟函数作为操作。在函数中,您可以使用 jQuery ajax 方法或直接 HTTP 请求编写服务器请求。完成后将服务器响应传回给 jTable。请记住,服务器响应应该是 jTable 所期望的 json 对象。
在此处阅读 jTable 文档


推荐阅读