Solved

Problems returning a recordset to AJAX call from ColdFusion

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to switch email hosts (part 2) 11 69
retrieving files from old server once DNS has changed 10 72
Apache SSL and mod_rewrite not working 8 157
SCCM vs Windows server 5 79
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…
Turn A Profile Picture Into A Cartoon Using Photoshop And Illustrator This tutorial will teach you how to make a cartoon style image out of a regular picture. I have tried to keep the tutorial as simple as possible. I used Adobe CS4 for this tuto…
The purpose of this video is to demonstrate how to insert an Iframe into WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Open Page or Post…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …

770 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