1

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

6
  • Use firebug and post request response you're getting from each. Commented Feb 21, 2011 at 11:39
  • {"COLUMNS":["CONTACTID","CONTACTFIRSTNAME","CONTACTLASTNAME","CONTACTMOBILE","CONTACTEMAIL","NOTES","CONTACTADDED"],"DATA":[]} is what firebug shows for the second one - I'm going to check (again) that the query returns data in SQL Commented Feb 21, 2011 at 12:30
  • The query definitely generates a result in SQL - the JSON returned in the frist example is similar - but has values as follows Commented Feb 21, 2011 at 12:34
  • `{"ROWCOUNT":2,"COLUMNS":["JOB_ID","TITLE"],"DATA":{"JOB_ID":[118,119],"TITLE":["MOD(R).0907","Feb 11 Demonstration Job"] Commented Feb 21, 2011 at 12:35
  • Assuming "arguments.alpha" is used in the query, did Firebug confirm that your JS is passing a rational value for alpha? Commented Feb 21, 2011 at 13:45

2 Answers 2

1

This is a longshot, but your function name is "getContacts" and, presumably, based on your code snippet, your query is called "getContacts".

I'm wondering if there's some bizarre collision happening there. Try renaming your query (and changing the "return" line as well) to something totally unique (be sure to VAR scope it too!)

edit: blah - your first CFC does that too, and it works. Well, try it anyway, who knows...

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks Edward - changed the query name etc - same result. I'm thinking that the obvious difference between the tho JSON returns is that one has ROWCOUNT and the other doesn't. I'm assuming that indicates that the query is not returning any rows.
I've confirmed that the second query/cfc is returning data - it's just not displaying the return format that is displaying looks like:
{"ROWCOUNT":3,"COLUMNS":["JOB_ID","TITLE"],"DATA":{"JOB_ID":[120,121,122],"TITLE":["Feb 11 Demonstration Job","Feb 11 Demonstration Job number three","Feb 11 Demonstration Job number four"]}}
and the one that's not displaying looks like:
{"COLUMNS":["CONTACTID","CONTACTFIRSTNAME","CONTACTLASTNAME","CONTACTMOBILE","CONTACTEMAIL","NOTES","CONTACTADDED"],"DATA":[[44,"Simon","Hine2",6.10417260088E11,"[email protected]",null,"February, 12 2011 00:00:00"]]}
|
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.