CFC JSON输出 - 显示查询结果时出现的问题 [英] CFC JSON Output - Issue with displaying query results
问题描述
这是一个很长的问题 - 有很多细节,所以首先为此道歉 - 但我不知道如何以一个更简单的方式问这个问题。
我有两个CFC,都设计为从查询返回JSON,然后我使用jquery显示结果。
第一个CFC看起来像这样:
< cfcomponent output =no>
< cffunction name =getRequestsaccess =remotereturntype =query>
< cfset var status =#arguments.status#>
<运行一些查询>
< cfreturn getRequests>
< / cffunction>
显示使用以下:
$。getJSON(getRequests.cfc?method = getRequests& returnformat = json& queryFormat = column ,{status:1},function(res,code){
if(res.ROWCOUNT> 0){
for(var i = 0; is =< div class ='dPostTxt'>< img class ='icon01'src ='images / icon01.png'/>< h4>+ res.DATA.TITLE [i] +< / h4>< p class ='txt01>面板< br />< span> RFQ ID< / span>< / p>
+< p class = txt02'>+ /*res.DATA.PANEL[+] + * /&br />< span>+ res.DATA.JOB_ID [i] +< / span> p"
+< p class ='txt03'>< span>< / span>+ /*res.DATA.RESPONSES + * /< br /> ;到期< / span>+ res.DATA.REQUIRED_DATE [i] +< / p>
+< img class ='sep02'src ='images / sep01.gif'/> ; < br />< div class ='clr'>< / div>< / div>;
};
}
else {
var s =对不起,没有匹配您的搜索;
}
$(#results)。html; s
} );
})
b
第二个CFC类似于:
< cfcomponent output =no>
< cffunction name =getContactsaccess =remotereturntype =query>
< cfset var alpha =#arguments.alpha#>
< run some query>
< / cfquery>
< cfreturn getContacts>
< / cffunction>
< / cfcomponent>
此CFC被调用,以下:
$(alphaindex)click(function(e){
var item = $ this).attr(title);
if(item ==)return
$ .getJSON(getContacts.cfc?method = getContacts& returnformat = json,{alpha:item},function(res,code){
if(res.ROWCOUNT> 0){
for(var i = 0; i< res.ROWCOUNT; i ++){
s + =< h3 class ='postTitle' ;+ res.DATA.CONTACTFIRSTNAME [i] + res.DATA.CONTACTLASTNAME [i] +< / h3>
+< p class ='postDesc'>+ res.DATA。 CONTACTEMAIL [i] +< / p>
+< p class ='postDesc'>+ res.DATA.CONTACTMOBILE [i] +< / p& 'clr'/>
};
s + =;
}
else {
var s =对不起,
}
$(#results)。html(s);
},json);
e.preventDefault();
})
这是返回JSON数据头 - 我不能告诉他们的区别是什么,或者在第二个例子中我会出错。
任何建议都可以感谢 - 对问题的长度再次抱歉。
Simon
解决方案一如既往)简单的事情,我错过了。我需要在第二个示例中添加& queryformat = column。
$。getJSON(getContacts.cfc?method = getContacts& ; returnformat = json& queryFormat = column
感谢Edward的帮助!
Simon
This is a long question - with a lot of detail - so first up apologies for that - but I'm not sure how to ask this in a briefer way.
I have two CFC's, both are designed to return JSON from a query, and then I'm using jquery to display the results.
The first CFC looks like this:
<cfcomponent output="no"> <cffunction name="getRequests" access="remote" returntype="query"> <cfset var status = #arguments.status#> <run some query> <cfreturn getRequests> </cffunction>
This is called and the result displayed using the following:
$.getJSON("getRequests.cfc?method=getRequests&returnformat=json&queryFormat=column",{"status":1}, function(res,code) { if(res.ROWCOUNT > 0){ for(var i=0; i<res.ROWCOUNT; i++) { s = "<div class='dPostTxt'><img class='icon01' src='images/icon01.png' /> <h4>" + res.DATA.TITLE[i] + "</h4> <p class='txt01>Panel <br /><span>RFQ ID</span></p>" + "<p class='txt02'>" + /*res.DATA.PANEL[i] +*/"<br /><span>" + res.DATA.JOB_ID[i] + "</span></p>" + "<p class='txt03'><span>Responses</span>" + /*res.DATA.RESPONSES +*/ "<br /><span>Due </span>" + res.DATA.REQUIRED_DATE[i] + "</p>" + "<img class='sep02' src='images/sep01.gif' /> <br /><div class='clr'></div></div>"; }; } else { var s = "Sorry, nothing matched your search."; } $("#results").html(s); },"json"); })
which all works fine.
The second CFC looks like this:
<cfcomponent output="no"> <cffunction name="getContacts" access="remote" returntype="query"> <cfset var alpha = #arguments.alpha#> <run some query> </cfquery> <cfreturn getContacts> </cffunction> </cfcomponent>
This CFC is called by and the data displayed by the following:
$(".alphaindex").click(function(e) { var item = $(this).attr("title"); if(item == "")return $.getJSON("getContacts.cfc?method=getContacts&returnformat=json",{"alpha":item}, function(res,code){ if(res.ROWCOUNT > 0){ for(var i=0; i<res.ROWCOUNT; i++) { s += "<h3 class='postTitle'>" + res.DATA.CONTACTFIRSTNAME[i] + res.DATA.CONTACTLASTNAME[i] + "</h3>" + "<p class='postDesc'>" + res.DATA.CONTACTEMAIL[i] + "</p>" + "<p class='postDesc'>" + res.DATA.CONTACTMOBILE[i] + "</p> <br class='clr' />" }; s += ""; } else { var s = "Sorry, nothing matched your search."; } $("#results").html(s); },"json"); e.preventDefault(); })
This is returning JSON data headers - but not data. I can't tell what the difference is, or where else I'm going wrong with the second example.
Any advice appreciated - apologies again for the length of the question.
Simon
解决方案Got it - as expected (and almost as always) something simple that I had missed. I needed to add &queryformat=column into the second example.
$.getJSON("getContacts.cfc?method=getContacts&returnformat=json&queryFormat=column"
Thanks to Edward for the help!
Simon
这篇关于CFC JSON输出 - 显示查询结果时出现的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!