Solved

Return JSON from a CFC

Posted on 2011-03-01
5
499 Views
Last Modified: 2012-05-11
I want to return login credentials in JSON format from a CFC. I am working on this, but don't think its right.

<cfcomponent name="loginCFC" displayname="loginCFC" output="false" hint="test login cfc for mobile app">
<cffunction name="getUser" access="remote" returnType="any" returnformat="JSON" output="false" hint="returns user info">
      <cfargument name="username" type="string" default="">
      <cfargument name="password" type="string" default="">

      <cfset var qGetUser = "">

      <cfquery name="qGetUser" datasource="#application.datasource#">
            select user_id, user_id_code, fname, lname, email
            from users
            where lower(email) = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.username#">
            and lower(password) = <cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.password#">
      </cfquery>

      <cfreturn qGetUser />
</cffunction>
0
Comment
Question by:theideabulb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

by:Jones911
ID: 35013145
What exactly do you want returned?
0
 

Author Comment

by:theideabulb
ID: 35013154
i want to return all the data that is in my query.
0
 
LVL 19

Accepted Solution

by:
Jones911 earned 500 total points
ID: 35013209
So ig you hit that cfc like http://url/cfc/loginCFC.cfc?method=getUser&username=a&password=b what do u get?
0
 
LVL 19

Expert Comment

by:Jones911
ID: 35013210
Because it should work
0
 

Author Closing Comment

by:theideabulb
ID: 35013236
HAHA! Your right it does work, i didn't try accessing it that way. I tried outputting it and dumping it.  Thanks.. Easy points for you :)
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
cfspreadsheet 15 130
ColdFusion 10 Error 2 84
What is the new coldfusion video tag for CF 11 or CF2016 for HTML5 playback 3 67
Coldfusion cfscript DELETE function 7 49
This article  is about submitting  form through  ColdFusion.Ajax.submitForm to the action page and send a response back in JSON format which later can be decoded using ColdFusion.JSON.decode. By this way you can avoid the usual page refresh for subm…
Sometimes databases have MILLIONS of records and we need a way to quickly query that table to return the results me need. Sure you could use CFQUERY but it takes too long when there are millions of records. That is why SOLR was invented. Please …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Suggested Courses

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question