问题,同时填充JQuery数据到ColdFusion中的Jquery数据表
问题描述:
我正在使用coldFusion 2016,当我将json数据放到我的Jquery数据表时,我面临着一个问题。该数据表只显示处理消息。 JSON结果似乎没有错误,但我不知道是什么问题。问题,同时填充JQuery数据到ColdFusion中的Jquery数据表
这里是我的DataTable实现
<head>
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
<link href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet">
<script type="text/javascript">
var table = '';
$(document).ready(function() {
table = $('#example').DataTable({
\t "bProcessing": true,
"bServerSide": true,
\t \t "ajax": "uploadProcess.cfc?method=getDetails&partyId=100004",
\t \t "sPaginationType": "full_numbers",
\t \t "oLanguage": {
\t \t \t \t "sProcessing": "Wait please...",
\t \t \t \t "sZeroRecords": "No records found.",
\t \t \t \t "sInfo": "Users from _START_ to _END_ of _TOTAL_ total",
\t \t \t "sInfoEmpty": "Users from 0 to 0 of 0 total"
\t \t \t \t },
\t \t "aoColumns": [
{ "data": "ID" },
{ "data": "ORG_NAME" },
{ "data": "TYPE" },
{ "data": "PATH" },
{ "data": "URL" },
{ "data": "DELETE" }
]
});
});
</script>
</head>
<body>
<div id="dataDiv">
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Id</th>
<th>File Name</th>
<th>Type</th>
<th>Path</th>
\t \t \t \t <th>Preview</th>
\t \t \t \t <th>Delete</th>
</tr>
</thead>
</table>
</div>
</body>
这里是我的uploadProcess.cfc
<cfcomponent>
<cffunction name="getDetails" access="remote" returnFormat="json">
\t <cfargument name="partyId" type="string" required="yes">
\t <cfparam name="arguments.iDisplayStart" default="0">
\t <cfparam name="arguments.iDisplayLength" default="10">
\t <cfparam name="arguments.iSortCol_0" default="UploadFileID">
\t <cfparam name="arguments.sSortDir_0" default="ASC">
\t <cfparam name="arguments.sEcho" default="1">
\t
\t <cfstoredproc procedure="get_upload_file_details" datasource="standout">
\t <cfprocparam value="#partyId#" cfsqltype="CF_SQL_INT">
\t <cfprocparam value="#arguments.iDisplayStart#" cfsqltype="CF_SQL_INT">
\t <cfprocparam value="#arguments.iDisplayLength#" cfsqltype="CF_SQL_INT">
\t <cfprocparam value="#arguments.iSortCol_0#" cfsqltype="CF_SQL_VARCHAR">
\t <cfprocparam value="#arguments.sSortDir_0#" cfsqltype="CF_SQL_VARCHAR">
\t <cfprocresult name="getUploadDtls">
\t </cfstoredproc>
\t <cfset userArray = arrayNew(1)> \t
\t
\t <cfloop query="getUploadDtls">
\t <cfif UserSessionID eq "">
<cfset deleteLink = "<span class='delete-link link'>Delete</span>" />
<cfelse>
<cfset deleteLink = "">
</cfif>
\t \t <cfset userStruct = {}>
\t \t <cfset userStruct.ID = UploadFileID>
\t \t <cfset userStruct.ORG_NAME = OriginalFileName>
\t \t <cfset userStruct.GEN_NAME = SystemFileName>
\t \t <cfset userStruct.TYPE = DocumentName>
\t \t <cfset userStruct.PATH = FilePath>
\t \t <cfset userStruct.URL = "<a href='renderpdf.cfm?path=#FilePath#&name=#OriginalFileName#' target='_blank'>Preview</a>">
\t \t <cfset userStruct.DELETE = deleteLink> \t \t
\t \t <cfset arrayAppend(userArray, userStruct) >
\t </cfloop>
\t <cfif getUploadDtls.RecordCount GT 0>
<cfset firstRow = queryGetRow(getUploadDtls,1)>
\t <cfset record_count = firstRow.record_count>
\t <cfelse>
\t <cfset record_count = 0>
</cfif>
\t <cfset returnStruct = {}>
\t <cfset returnStruct['iTotalRecords'] = record_count>
\t <cfset returnStruct['iTotalDisplayRecords'] = record_count>
\t <cfset returnStruct['sEcho'] = arguments.sEcho>
\t <cfset returnStruct['aaData'] = userArray>
\t <cfset resultsJSON = SerializeJSON(returnStruct)>
\t <cfreturn resultsJSON>
</cffunction>
</cfcomponent>
JSON的[R下面给出从我的功能返回的结果。
{""aaData"":[{""GEN_NAME"":""sample_489.pdf"",""PATH"":""C://Standout/web_uploads/100004/Medical Reports/sample_489.pdf"",""DELETE"":"""",""ORG_NAME"":""sample.pdf"",""ID"":77,""TYPE"":""Medical Report"",""URL"":""<a href='renderpdf.cfm?path=C://Standout/web_uploads/100004/Medical Reports/sample_489.pdf&name=sample.pdf' target='_blank'>Preview</a>""}],""iTotalDisplayRecords"":1,""iTotalRecords"":1,""sEcho"":1}"
我想不出有什么问题可以有人帮忙吗?
答
我将首先删除包裹结构的那些花括号。
如果你只是传入你的结构,SerializeJson()已经很好地工作了。
看起来您的JSON无效,可能导致错误,或者您的数据表配置不正确。
老实说,我建议只是用cfloop填满你的桌子。
<cfloop query="myQuery">
<tr>
<td>
#myQuery.someData#
</td>
...
</tr>
</cfloop>
如果您在加载页面时加载数据,此解决方案也可能正常工作。
数据表API有时可能会被点击或错过。
问题是你的JSON返回它是无效的。尝试https://jsonlint.com验证您的JSON的JSON应该像{ \t “aaData”:[{ \t \t “GEN_NAME”: “sample_489.pdf”, \t \t “PATH”:“C:/ /突出/ web_uploads/100004 /医疗报告/ sample_489.pdf”, \t \t “DELETE”: “”, \t \t “ORG_NAME”: “sample.pdf”, \t \t “ID”:77, \t \t “TYPE”:“Medical Report”, \t \t“URL”:“Preview” \t}], \t “iTotalDisplayRecords”:1, \t “iTotalRecords”:1, \t “sEcho”:1 } –
我已经给returnFormat = “json的” 在我的cffunction,所以JSON在前面到达将按照您指定的格式使用正确的格式。 –