Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonegap using Coldfusion as a backend to retrieve data

I am trying to develop a phonegap app that will call to my coldfusion server and return data to the phone app. I have seen a couple of tutorials that do not explain the code on the server side(the .cfc file). Like this one... http://blog.ryanvikander.com/index.cfm/2012/3/28/Returning-Dynamic-Content-In-A-PhoneGap-App

I was hoping someone could provide some sample code of what the .cfc on my server would look like when it is receiving the request for data.

like image 754
Phil Baumert Avatar asked Dec 11 '25 13:12

Phil Baumert


1 Answers

Here's the example code from that link:

<!doctype html>
<html>
    <head>
        <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width" />
        <title>My App</title>
        <script src="phonegap.js" type="text/javascript" charset="utf-8"></script>
        <script src="jquery.js" type="text/javascript" charset="utf-8"></script>

        <script type="text/javascript">
            jQuery(document).ready(function() {
                $.ajax({
                    url:"http://www.ryanvikander.com/test.cfc?method=getdata",
                    success: function(data){
                        var content = $("#content");

                        content.html(data);
                    },
                    error: function(e){
                        console.log(e);
                    }
                });
            });
        </script>

    </head>
    <body>
        <div id="title_bar">Test</div>
        This is a test
        <div id="content"></div>
    </body>
</html>

The url http://www.ryanvikander.com/test.cfc?method=getdata doesn't have to be anything more than this:

<cfcomponent>

    <cffunction name="getdata" access="remote" output="false">

        <cfreturn "Hello World!" />

    </cffunction>


</cfcomponent>

Here, the success callback function will put the string "Hello World!" into <div id="content"></div>

If the function renderdata() returned a query, you could pass the querystring parameters returnformat=json and optionally queryFormat=column to have ColdFusion convert the query data into JSON. If the returned data is formatted in JSON, then you could iterate over that data to render HTML as in any website.

like image 195
Adrian J. Moreno Avatar answered Dec 13 '25 04:12

Adrian J. Moreno



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!