Greetings,
I have a silly question but I am a newbie. I am trying to make a cross-domain request (via ajax) using extjs4 library. As server side language I am using ColdFusion. The whole code that I have written so far is working on same domain. I need to separate static files (javascript, css, and html) placing them on Apache server and the dynamic content (cfm, CFC) placing them over Tomcat (openbd). So the front end scripts (on Apache->javascript mainly) making requests on Tomcat in order to fetch content. This definitely is cross-domain requests.
A code block that I am using in order to pull data (CFC) is:

Code:
<cfcomponent output="false">
<cfprocessingdirective pageencoding="utf-8">
<cfset setEncoding("URL", "utf-8")>

    <cffunction name="getContent" access="remote" returnFormat="JSON" output="false" >  
        <cfargument name="start" default="0"/>    
        <cfargument name="limit" default="1000"/>
        <cfargument name="id" default="0" required="false" type="numeric">
        <cfargument name="model" default="" required="false" type="any">

        <cfset var arrNomoi = ArrayNew(1)>
        <cfset var stcReturn = "">

        <!--- When going back to base state, ExtJS will make the function call with start set to 0. If this is the case
        we set it to 1 --->
        <cfset Arguments.start = Arguments.start + 1>


        <cfif arguments.model EQ 'n_2664_1998'>

            <cfquery name="getNomoi" datasource="ktimatologio">
                SELECT CONCAT_WS('_',id,model) AS id, id AS 'id1', CONCAT_WS(' ',title,fek,date) AS 'title', description, body, model
                FROM n_2664_1998
                WHERE id = #arguments.id#
                ORDER BY id ASC
            </cfquery>

        <cfelseif arguments.model EQ 'n_2308_1995'>

            <cfquery name="getNomoi" datasource="ktimatologio">
                SELECT CONCAT_WS('_',id,model) AS id, id AS 'id1', CONCAT_WS(' ',title,fek,date) AS 'title', description, body, model
                FROM n_2308_1995
                WHERE id = #arguments.id#
                ORDER BY id ASC
            </cfquery>

        <cfelseif arguments.model EQ 'n_3889_2010'> 

            <cfquery name="getNomoi" datasource="ktimatologio">
                SELECT CONCAT_WS('_',id,model) AS id, id AS 'id1', CONCAT_WS(' ',title,fek,date) AS 'title', description, body, model
                FROM n_3889_2010
                WHERE id = #arguments.id#
                ORDER BY id ASC
            </cfquery>  

        </cfif>

        <cfset arrNomoi = convertQueryToExtJS(getNomoi,Arguments.start,Arguments.limit)>

        <cfset stcReturn = {"data"=arrNomoi,dataset=#getNomoi.RecordCount#}>

        <cfreturn stcReturn>

    </cffunction>

    <cffunction name="convertQueryToExtJS" access="public" hint="Convert Query to JSON usable by ExtJS Grid" returntype="array">
        <cfargument name="qryData" type="query" required="true" hint="Query to convert">
        <cfargument name="intStart" type="numeric" required="true" hint="Start of Result Set">
        <cfargument name="intLimit" type="numeric" required="true" hint="How many records to return">

        <!--- For the Array --->    
        <cfset var i = 1>        
        <cfset var end = ((Arguments.intStart) + arguments.intLimit)-1>
        <cfset var arrNomoi = ArrayNew(1)>

        <cfloop query="qryData" startrow="#Arguments.intStart#" endrow="#end#">        
            <cfset stcNomoi = StructNew()>
            <cfset stcNomoi['id'] = #qryData.id#>
            <cfset stcNomoi['id1'] = #qryData.id1#>
            <cfset stcNomoi['title'] = #qryData.title#>
            <!---<cfset stcNomoi['fek'] = #qryData.fek#>
            <cfset stcNomoi['date'] = #qryData.date#>--->
            <cfset stcNomoi['description'] = #qryData.description#>
            <cfset stcNomoi['body'] = #qryData.body#>
            <cfset stcNomoi['model'] = #qryData.model#>
            <cfset arrNomoi[i] = stcNomoi>
            <cfset i = i + 1>            
        </cfloop>


        <cfreturn arrNomoi>

    </cffunction>

</cfcomponent>
The question is: how do I wrap the above function into a variable (named “callback”) and post it on client?

I have seen a similar code block on PHP but I don’t understand. Below is the PHP code block:

Code:
<?php
$callback = $_REQUEST['callback'];
// Create the output object.
$output = array('id' => 1, 'url' => 'loianegroner.com');
//start output
if ($callback) {
header('Content-Type: text/javascript');
echo $callback . '([' . json_encode($output) . ']);';
} else {
header('Content-Type: application/x-json');
echo json_encode($output);
} 
?>

With respect,

Tom

Greece