Solved

Problems returning a recordset to AJAX call from ColdFusion

Posted on 2006-06-12
4
322 Views
Last Modified: 2013-12-24
I have a stored procedure that's returning a recordset of locations as XML for use on a Google map. The procedure works fine and returns a valid XML file.

On the client side, I have some JavaScript that's using the prototype library to connect to this procedure and return the XML. For some reason, nothing is making it through to the callback function in javascript. If I try showing request.responseText to view the data, there's nothing there.

Strange thing is, I can save the XML output from the procedure as a static file - then load the static file using the same JavaScript and everything works like a charm. I know the data returned from the procedure is correct. I know the JavaScript is processing it correctly. I'm not sure where it's going wrong. I've experimented with MIME types, etc. but nothing's worked.


CF Code:

<cfstoredproc procedure="usp_get_all_locations" datasource="#application.datasource_wc#">
      <cfprocresult name=RS>
</cfstoredproc>
<cfprocessingdirective suppresswhitespace="Yes">
      <cfcontent type="text/xml">
      <cfoutput><?xml version="1.0" encoding="utf-8" ?>
      <locations>
            <cfloop query="RS">
                  <camp>
                        <ID>#RS.campID#</ID>
                        <Name>#XMLFormat(RS.campname)#</Name>
                        <Lgt>#RS.camplongitude#</Lgt>
                        <Lat>#RS.camplatitude#</Lat>
                  </camp>
            </cfloop>
      </locations>
      </cfoutput>
</cfprocessingdirective>


JS Code:

var url = 'getFunctions.cfm';
var request = new Ajax.Request(url,{method:'get',parameters:params,onSuccess:loadMarkers,onFailure:showError});

function loadMarkers(request){
        var xml = request.responseXML;
        var camps = xml.getElementsByTagName("camp");
        alert(camps.length);
}


In this example, if I keep the url as the .cfm file, the loadMarkers function returns "0" as the length of the camps array. If I change the url variable to the resulting XML output, it returns "80" as the length.

I'm at a loss.
0
Comment
Question by:braincrumbs
4 Comments
 

Expert Comment

by:rragledavis
ID: 16910811
The first place I would look is at the data returned.   Since your data becomes part of the javascript output any unacceptable punctuation will break it. If you dont see it right away try seeing if the first record will show and then add the enxt record and so on until it breaks.
0
 

Author Comment

by:braincrumbs
ID: 16912781
I have tried that. As I said, it's actually returning valid XML. I could save the output to a static file, then the map would load the static file without a problem.

I've since switched from returning the XML to using CFAJAX to retreive the data. That is working fine.

Thanks for your help.
0
 

Accepted Solution

by:
CetusMOD earned 0 total points
ID: 17113557
PAQed with points refunded (500)

CetusMOD
Community Support Moderator
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When deciding to adopt any help desk solutions many factors should be explored before taking decisions. This will change from business to another but in general there are some kind of rule of thumb. Here are some quick tips: Do we need only ticket…
In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…
The purpose of this video is to demonstrate how to prevent comment spam on a WordPress Website. This will be demonstrated using a Windows 8 PC. Plugin Akismet will be used. Go to your WordPress login page. This will look like the following: myw…

759 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now