简体   繁体   English

如何在JQuery jtable中配置REST HTTP方法

[英]How to configure REST HTTP Methods in JQuery jtable


I cannot find any example in jQuery jtable to use a different HTTP method for my actions. 我在jQuery jtable中找不到任何使用不同HTTP方法进行操作的示例。 As a matter of fact, my back-end uses a @GET to list data @POST to add Data, @DELETE to remove data and @PUT to update data. 事实上,我的后端使用@GET列出数据@POST来添加数据,使用@DELETE来删除数据,使用@PUT来更新数据。 However, it seems that jQuery uses an HTTP POST for all actions: 但是,似乎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');
    });

Any idea how to set a specific HTTP method for each action? 知道如何为每个动作设置特定的HTTP方法吗?

When you give jTable a URL as an action, it will use standard jQuery ajax to execute the URL. 当您将jTable作为操作提供给URL时,它将使用标准的jQuery ajax来执行URL。
However you can instead supply a deferred function as an action. 但是,您可以将延迟函数作为操作提供。 In the function you write the server request, either using jQuery ajax methods or direct HTTP requests. 在函数中,您使用jQuery ajax方法或直接HTTP请求编写服务器请求。 On completion pass the server response back to jTable. 完成后,将服务器响应传递回jTable。 Remember the server response should be a json object as expected by jTable. 请记住,服务器响应应该是jTable所期望的json对象。
Read the jTable documentation here 在这里阅读jTable文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM