Kevin Sherman
Kevin Sherman

Reputation: 63

ColdFusion CFC loaded through AJAX returns empty response

I'm having trouble calling a CFC through a jQuery ajax call. I've read at least a dozen articles/Overflows on the topic but cannot get a basic "Hello World" to return to the page. My environment is running ColdFusion 11 on Window 2008 R2 and IIS7.5

Here is my CFC:

<cfcomponent displayname="BU_ldaptest" extends="ADF.apps.BU_Utils.components.App" hint="BU_ldaptest.">
<cfproperty name="version" value="1_0_0">
    <cffunction name="helloWorld" access="remote" returntype="string" output="false">
        <cfreturn "Hello World!">
    </cffunction>
</cfcomponent>

And here is my CFM:

<cfoutput>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
#application.BU_Utils.BU_ldaptest.helloWorld()#
<button onClick="loadCFC();">Load</button>
<script>
    function loadCFC() {
        $.ajax({
            type: "post",
            url: "/ADF/apps/BU_Utils/components/BU_ldaptest.cfc?method=helloWorld",
            cache: false,
            success: function(msg) {
                $("##result").html(msg);
                console.log(msg);
            },
            error: function(msg) {
                $("##result").html("Failed");
            }
        });
        console.log("function execute");
    };
</script>
<div id="result">...</div>
</cfoutput>

In the CFM, that "#application.BU_Utils...#" variable does correctly print "Hello World!" in the browser.

I do not have any Web Services setup in the CF Admin interface, are they required for something like this to work? I also know that I'll eventually want my cfc to return JSON, which it will once I can just get this simple string to print out. I've gone through this Overflow over and over... Invoke ColdFusion function using AJAX

Thank you.

Upvotes: 2

Views: 751

Answers (1)

Tyson Paul
Tyson Paul

Reputation: 1

in my application i have to display a table using ajax, so i wraped my table in cfsavecontentand returned the cfsavecontent variable.

Example:

    <!--- declaring variable to return to ajax --->
    <cfset VAR PlayList =''>


    <!--- Saving content inside cfsavecontent to playlist variable --->
    <cfsavecontent variable="PlayList">

        <table border="1" class="companytab1">
        <thead>
            <tr class="header">
                <th>SlNo</th>
                ....
                <th>Company Name</th>
            </tr>
        </thead>
            <tbody>
                <tr>
                <!--- SlNo--->
                <td align="center" >1</td>
                ....
                <!--- Company Name--->
                <td align="center" >Asdf</td>
            </tbody>
        </table>

    </cfsavecontent>

<cfreturn PlayList>

Upvotes: 0

Related Questions