Carla
Carla

Reputation: 3390

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?

Upvotes: 0

Views: 176

Answers (1)

misterP
misterP

Reputation: 185

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

Upvotes: 0

Related Questions