2017-10-20 3 views
0

ColdFusion 2016을 사용하고 있으며 json 데이터를 Jquery 데이터 테이블에 넣을 때 한 가지 문제가 있습니다. 데이터 테이블은 처리 메시지 만 표시합니다. JSON 결과에 오류가있는 것 같지만 문제가 무엇인지 알 수 없습니다. 여기 JSON 데이터를 ColdFusion의 Jquery 데이터 테이블에 채우는 동안 문제가 발생했습니다.

<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 내 데이터 테이블 구현 내 cffunction에서 돌아 오는 esult가 아래에 주어집니다.

{""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}"

나는 문제가 누군가가 도움을 줄 수 있는지 알아낼 수 없습니다?

+0

JSON 반환 문제가 유효하지 않습니다. 당신의 JSON은 { \t "aaData"처럼해야 https://jsonlint.com에 당신의 JSON을 확인하는 시도 : [{ \t \t "GEN_NAME": "sample_489.pdf" \t \t "PATH": "C :// 탁월한 성과를내는/web_uploads/100004/의료 리포트/sample_489.pdf " \t \t은"삭제 ":" ", \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 "서초": 1 } –

+0

가 이미 주어진 returnFormat = 내 cffunction의에서 "JSON", 그래서 JSON이 앞에 도달 -end는 지정한 형식대로 표시됩니다. –

답변

0

먼저 구조체를 감싸는 중괄호를 제거합니다.
SerializeJson()은 구조체를 전달하면 이미 잘 작동합니다.

JSON이 유효하지 않아 오류가 발생했거나 데이터 테이블이 제대로 구성되지 않은 것 같습니다.

정직하게는 cfloop으로 테이블을 채우는 것이 좋습니다.

<cfloop query="myQuery"> 
    <tr> 
     <td> 
      #myQuery.someData# 
     </td> 
     ... 
    </tr> 
</cfloop> 

페이지로드시 데이터를로드하는 경우이 솔루션이 올바르게 작동 할 수도 있습니다.
데이터 가능 API는 때로는 맞거나 손실 될 수 있습니다.