jquery - 如何在 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 方法吗?
解决方案
当你给 jTable 一个 URL 作为一个动作时,它会使用标准的 jQuery ajax 来执行这个 URL。
但是,您可以改为提供延迟函数作为操作。在函数中,您可以使用 jQuery ajax 方法或直接 HTTP 请求编写服务器请求。完成后将服务器响应传回给 jTable。请记住,服务器响应应该是 jTable 所期望的 json 对象。
在此处阅读 jTable 文档
推荐阅读
- html - 使用 HTML 和 CSS 设计记分牌
- ios - .fbx 文件与 ARKit 中的动画
- ios - 如何使用帮助贝塞尔路径在swift 4中使用箭头创建虚线?
- python - 熊猫中列的多个索引
- typescript - 使用打字稿编译器api时如何解决未解释的语句问题?
- powershell - 直接喷射参数(不将它们保存在临时变量中)
- xcode - 我想使用 UISearchBar 在 TableView 中搜索
- frontend - Odoo 11.0 仅在渲染模板时加载 css/scripts 或其他内容
- c# - 从 JSON 加载对话框 - BotFramework V4
- git - git 从所有分支中删除文件和历史记录