Question

cffunction returntype="xml" problem

Asked by: remmuh

I am attempting to implement an AJAX form and it works fine until I need to provide communication from the CFC to the AJAX form. Unfortunately when sending data back to the AJAX form (via xmlHttp.responseXML). Well I can output XML from my CFC just fine, only responseXML only will recognize the document if the mime is set to text/xml. When the CFC outputs XML it does not set the header information to text/xml. Is there a way to do this?

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-11-24 at 11:20:37ID21642474
Tags

cffunction

,

xml

Topics

ColdFusion Application Server

,

Extensible HTML (XHTML)

Participating Experts
1
Points
500
Comments
7

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. CFC's and Variable Scope/Persistence
    I'm looking to create a web service that can be made available to anyone. I want to start by creating the component object, running an initialization method to set the user's unique keys, and then make a number of methods available that will use those keys for their operatio...
  2. help with CF/Ajax/Spry/Xml
    I need help with Coldfusion and some Ajax using Spry from Adobe. For some reason, I have to use XML as a go between from my ODBC database and the AutoSuggest box on my form. As of now, I am getting a "not well formed" parsing error. This is the CFfunction; <cf...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: wulfshaydePosted on 2005-11-24 at 19:20:46ID: 15358864

If you're using coldfusion you should take a look at CFAjax... it's a solid project and I use it because I had similiar quirks with AJAX.

Look here: http://www.indiankey.com/cfajax/

I have currently implemented it in our company extranet, makes things super! :)

Also you can return Coldfusion Structs and Arrays straight to the API and it will parse them and treat them as javascript objects and arrays. If you've gotten this far with AJAX, I'm confident that CFAjax should be a breeze for you. If you have any other q's give me a holler.

 

by: remmuhPosted on 2005-11-24 at 22:23:04ID: 15359352

Well wulfshayde, I did consider that but I wasn't sure about it. I figured out a work around for now, but it isn't ideal. I would love to just be able to interface directly with the CFC, but the workaround I created for now doesn't allow me to do that.

What I am doing for now is I am sending the request from the form to a processing page which basically creates an instance of the cfc, runs the function and the function returns XML to processing page. From there that page writes the xml to a temporary XML file on the server and the page CFLOCATION's the process to the XML file. And it actually worked quite well. But that is kind of a clumpy (mickey mouse) way of doing it and I would prefer not. If CFAJAX can allow me to do it better I will definitely consider it.

I do have a few questions that I can't seem to gather from the website. How is it actually installed? Is it a bunch of CFCs? How do I access the various functions?

 

by: wulfshaydePosted on 2005-11-24 at 23:03:36ID: 15359406

*cracks knuckles*

Let me give you an example. :)

I've downloaded the CFAjax package and unzipped the cfajax/core/ folder into my application parent folder. Lets say for example my application is called App1 and its located at C:\InetPub\wwwroot\App1\ (for a windows box). I create a folder called ajax in the App1 folder and unzip the core folder (from the package) into the newly created ajax folder. I can now cfinclude all my cfajax stuff into my application. Lets say for example I want to use cfajax on my Index.cfm file (because I generally create Index.cfm as a template which includes other files).

So to clarify, Cfajax would be located in:

        C:\Inetpub\wwwroot\App1\ajax\

And the index file would be in:

        C:\Inetpub\wwwroot\App1\

I would put this into the <head></head> of the Index.cfm file.

C:\InetPub\wwwroot\App1\Index.cfm - <head></head>
========================================
      <script type='text/javascript' src='ajax/core/prototype.js'></script>
      <script type='text/javascript' src='ajax/core/suggest.js'></script>
      <script type='text/javascript' src='ajax/core/engine.js'></script>
      <script type='text/javascript' src='ajax/core/util.js'></script>
      <script type='text/javascript' src='ajax/core/settings.js'></script>

By loading those js files you have now included everything necessary for any function of cfajax. One thing of particular interest to note is the settings.js file, this is where you set which cfm files contain the functions that you wish to use. Now I also have Application Scope components which I like to access; but cant be done directly from ajax of any form that I have found, however I will show you a solution for this.

The settings.js file should look like this:

C:\InetPub\wwwroot\App1\ajax\core\settings.js
==================================
//the ajax component scope name
_cfscriptLocation = "ajax/functions.cfm";

//custom error handling
function errorHandler(message)
{
      $('disabledZone').style.visibility = 'hidden';
    if (typeof message == "object" && message.name == "Error" && message.description)
    {
        alert("Error: " + message.description);
    }
    else
    {
        alert(message);
    }
};

_cfscriptLocation is how you are going to access all functions located in functions.cfm. You will notice that I have included it as ajax/functions.cfm because it is located at C:\Inetpub\wwwroot\App1\ajax\ and it is included in index.cfm which is located at C:\Inetpub\wwwroot\App1\. These mappings may change with your application, pay specific attention to them. Now to use application/session level components in the functions I did this:

C:\InetPub\wwwroot\App1\ajax\functions.cfm
=================================
<cfinclude template="core/cfajax.cfm">

      <cffunction name="posLookup">
            <cfargument name="departmentID" required="yes" type="string">
            <cfset var deps = Application.cons.CorpController.getPositionsByDepartmentID(val(arguments.departmentID)) />
            <cfreturn deps>
      </cffunction>

You will notice that you have to include cfajax.cfm in any of the functions.cfm files that you create. Include relative from where the functions file resides. You will also see here that I dont have to worry about specifying a returntype, and I can return, string, query, number, struct, array, list, and they will all get converted accordingly. :)

To use in a file lets go back to index.cfm and place the following into the <head></head> tags under the includes:

C:\InetPub\wwwroot\App1\Index.cfm - <head></head>
=====================================
<cfoutput>
            <script language="javascript">
                  
                  function getPositions()
                  {
                        var departmentID = DWRUtil.getValue("departmentID");
                        DWREngine._execute(_cfscriptLocation, null, 'posLookup', departmentID, getPositionResult);
                  }
                  
                  function getPositionResult(posArray)
                  {
                        DWRUtil.removeAllOptions("positionID");
                        DWRUtil.addOptions("positionID", posArray, "POSITIONID", "POSITION");
                        DWRUtil.setValue("positionID","#myProfile.positionID#");
                  }
                  
                  function init()
                  {
                        DWRUtil.useLoadingMessage();
                        DWREngine._errorHandler =  errorHandler;
                        getLocations();
                  }
                  
            </script>
</cfoutput>

With a bit of looking at getPositions() you will see I call a function from the function file with the following:

        var departmentID = DWRUtil.getValue("departmentID");
        DWREngine._execute(_cfscriptLocation, null, 'posLookup', departmentID, getPositionResult);

The DWREngine and DWRUtil will do most of your work for you. DWRUtil.getValue is getting the value of the select with the name/id of 'departmentID'. In this case I 'execute' a function from _cfscriptLocation. null is required. 'posLookup' is function in the functions.cfm file I want to call. departmentID is the variable I am passing in (you will see I set departmentID = DWRUtil.getValue("departmentID"); above the execute). getPositionResult is the return function, this function will get passed the return data and run.

Now to getPositionResult(posArray) you will see the following:

      DWRUtil.removeAllOptions("positionID");
      DWRUtil.addOptions("positionID", posArray, "POSITIONID", "POSITION");
      DWRUtil.setValue("positionID","#myProfile.positionID#");

*DWRUtil.removeAllOptions("positionID") - clears the select list and removes all options from it.
*DWRUtil.addOptions("positionID", posArray, "POSITIONID", "POSITION") - fills the select 'positionID' with the Array(coldfusion query) values of POSITIONID for the value and POSITION for the display. Take special notice of the UPPERCASE letters. when referring a coldfusion query column with cfajax you must use all UPPERCASE regardless of the original case.
*DWRUtil.setValue("positionID","#myProfile.positionID#") - sets the select default value after fill to a dynamic value of myProfile.positionID.

Now add this to the <body> tag:

        onLoad="init();"

And in the body I have this:

<cfform name="form" method="post">
<table cellpadding="2" cellspacing="1" class="details" width="400">
<tr>
<th class="required">Department </th>
<td><cfselect name="departmentID" onChange="getPositions()" class="ajaxfield" style=" width: 86%; " /></td>
</tr>
<tr>
<th class="required">Position </th>
<td> <cfselect name="positionID" class="ajaxfield" style=" width: 86%; " /></td>
</tr>
<tr>
<th>Click to Update >></th><td><input type="hidden" name="personnelID" value="#myProfile.personnelID#" /><input type="hidden" name="active" value="#myProfile.active#" /><input type="submit" name="Submit" value="Update" /></td>
</tr>
</table>
</cfform>

You can see that on the cfselect (which could just as easily be select) I call getPositions() on the onChange method. I hope I haven't completely confused you. but I will say, once you get it working, its so easy its insane. There is some decent documentation on it to, and a yahoo group.

}Wulf{

 

by: remmuhPosted on 2005-11-24 at 23:55:59ID: 15359539

Well Wulf, I graciously accept all the input and time that you have put into this answer. Though I was a tad confused on a couple of parts that you were talking about, I was quite interested at seeing how much less code you were using to accomplish such diffcult tasks. I still have not made my decision, but you did answer my question exactly on the inclusion of the cfajax code. I think what I need to do is just sit down with it and try a couple of things for testing and to play around with it before I decide to implement it into the site I am working on. Based on your enthusiasm of the product, I must say that once I get to know it I will be very happy with it. I am going to take a look at the extensive documentation that you speak of and drill it down to figure out what I shall do.

Thank you very much for your time that you spent on this question. It is people like you that keep me coming back to this great site! You fully earned the points, enjoy!

 

by: remmuhPosted on 2005-11-25 at 00:02:03ID: 15359556

Ok, I was just reading an article on coldfusion journal that kind of cleared up some of the confusion. Any functions that I want to use to interact with CFAJAX, I need to put in a single file and point the settings.js var to that location of the functions file? This is somewhat disappointg as I am very structured in my file layout and would like to separate functions into their respective cfc files in packages and what not. However, I am also very flexible, especially when it comes to new and great technologies!

 

by: remmuhPosted on 2005-11-25 at 00:07:02ID: 15359566

I just answerd my own question:

_cfscriptLocation = "http://www.realradioactive.org/ajax/examples/functions.cfm";
_cfscriptAmazonLocation = "http://www.realradioactive.org/ajax/app/amazon/functions.cfm";
_cfscriptVotingLocation = "http://www.realradioactive.org/ajax/app/voting/functions.cfm";
_cfscriptYahooLocation = "http://www.realradioactive.org/ajax/app/yahoo/functions.cfm";

I would just define multiple locations and use those in the execute function. I am liking this so far!

 

by: wulfshaydePosted on 2005-11-25 at 14:01:19ID: 15362852

Thank you very much. It's hard trying to explain new technologies, but I'm glad you found some additional resources to help clarify the points that I confused you with. ;)

Thank you for the grade and points, it's people like you that keep me coming back also. And yes, you can define as many locations as you can for fuction files (I only use one because its a managed app with Application Scope Components). I hope you'll find it as useful a tool as I did.

Cheers!

}Wulf{

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...