简体   繁体   中英

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. 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. However, it seems that jQuery uses an HTTP POST for all actions:

<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?

When you give jTable a URL as an action, it will use standard jQuery ajax to execute the 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. On completion pass the server response back to jTable. Remember the server response should be a json object as expected by jTable.
Read the jTable documentation here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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