Solved

Problems returning a recordset to AJAX call from ColdFusion

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

Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Collapseable list of URLs. 10 144
Add server behaviors to Dreamweaver CC 2015 2 252
Problem to echo 6 116
http to https 3 82
Now that Expression Web 4.0 (http://www.microsoft.com/expression/products/Upgrade.aspx) is free if you buy or have the full version of Expression Web 3.0, now is the best time to  migrate from FrontPage to Expression Web (http://www.frontpage-to-exp…
What You Need to Know when Searching for a Webhost Provider
The purpose of this video is to demonstrate how to make a WordPress Site faster and smaller in size by cleaning up the database. This will be demonstrated using a Windows 8 PC. Plugin WP Optimize will be used. Go to your WordPress login page. T…
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

739 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