我使用 jqGrid API 在 view.jsp 中创建了一个表,并将该表数据保存到一个 javascript 对象中,现在我想使用 Liferay portlet 将该表数据(javascript 对象)保存到数据库中?
我使用ajax向后端发送数据
<div id="jgDiv1">
<table id="JQGrid1" >
</table>
<div id="pager"></div>
</div>
<button onclick="griddata()">Submit</button>
<script>
var dataArray = [];
$("#JQGrid1").jqGrid({
datatype: "local",
data: dataArray,
colNames:["Sr", "Submited By","Valued To","Due Date", "Pay Notice By","Pay Less Notice By","Final Date for payment", "Action"],
colModel: [
{ name: 'id', index: 'id', sorttype:'int',key: true, align: "center", width: 55, editable: false, editoptions: { readonly: true, size: 10 } },
{ name: "SubmitedBy", width: 100, formatter: "date", align: "center", editable: true, editoptions: { size: 10 } },
{ name: "valuedTo", editable: true,formatter: "date", align: "center", editoptions: { size: 10 } },
{ name: "DueDate", editable: true,formatter: "date", align: "center", editoptions: { size: 10 } },
{ name: "PNB", editable: true,formatter: "date", align: "center", editoptions: { size: 10 } },
{ name: "PLNB", editable: true,formatter: "date", align: "center", editoptions: { size: 10 } },
{ name: "FD", editable: true,formatter: "date", align: "center", editoptions: { size: 10 } },
{name: 'myac', width:80, fixed:true, sortable:false, resize:false, formatter:'actions',
formatoptions:{keys:true}},
],
sortorder: "desc",
viewrecords: true,
rowNum:20,
pager:'pager',
caption:"Payment Cycle Terms"
}).navGrid('#pager',{edit:false,add:true,del:false,search:false,refresh:false,},
{
width:400,
height:330,
closeAfterEdit:true,
onInitializeForm:function(){
$('#SubmitedBy,#valuedTo,#DueDate,#PNB,#PLNB,#FD').datepicker({
changeMonth:true,
changeYear:true,
changeDay:true,
})
}
},
{
width:400,
height:330,
closeAfterAdd:true,
onInitializeForm:function(){
$('#SubmitedBy,#valuedTo,#DueDate,#PNB,#PLNB,#FD').datepicker({
changeMonth:true,
changeYear:true,
changeDay:true,
})
}
});
function griddata(){
var gridData = jQuery(JQGrid1).getRowData();
var postData = JSON.stringify(gridData);
console.log("jqGrid data:\n" + postData);
$.ajax({
method:'POST',
url: "<%=downloadExcel.toString()%>",
data : {
jgGridData: postData
},
dataType:"json",
contentType: "application/json; charset=utf-8",
success: function(response, textStatus, xhr) {
console.log("success");
},
error: function(xhr, textStatus, errorThrown) {
console.log("error");
}
});
}
我使用 jqGrid API 在 view.jsp 中创建了一个表,并将该表数据保存到一个 javascript 对象中,现在我想使用 Liferay portlet 将该表数据(javascript 对象)保存到数据库中?