Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problems returning a recordset to AJAX call from ColdFusion

Posted on 2006-06-12
4
Medium Priority
?
348 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

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…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
The purpose of this video is to demonstrate how to automatically show related posts at the bottom of a blog post in WordPress. This will be demonstrated using a Windows 8 PC. Plugin “Yet Another Related Posts Plugin” will be used. Go to your…
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…
Suggested Courses

636 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