Solved

Problems returning a recordset to AJAX call from ColdFusion

Posted on 2006-06-12
4
330 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
This guide will walk you through the essential considerations and tech stack for building scalable websites. Know how to grow your business the smart way!
The purpose of this video is to demonstrate how to manually back up a WordPress Database. This will be demonstrated using a Windows 8 PC. The Host used will be IPage.com Log into your Hosting account. IPage will be used for demonstration : Locat…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

832 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