Not getting response from cfc with jquery ajax call

This is driving me nuts. I’ve been reading post after post after post and I like I have this set up correctly and it’s posting correctly, but nothing is happening. Here’s the setup:


<cfcomponent output="false" access="remote">
	<cffunction name="list" returntype="query" output="false" access="remote" description="returns a list of locations based on zip code provided.">
		<cfargument name="zip" type="string" required="true" default="" />
		<cfargument name="radius" type="string" required="true" default="FORM.radius" />
		<cfif NEQ "00000">
			<cfquery name="target_zip" datasource="#APPLICATION.dsn#">
				SELECT latitude, longitude
				FROM zips
				WHERE zip = '';
			<cfquery name="available_locations" datasource="#APPLICATION.dsn#">
			    SELECT zip, city, state, latitude, longitude, 
			    ROUND((ACOS((SIN(#target_zip.latitude#/57.2958) * SIN(latitude/57.2958)) + 
				(COS(#target_zip.latitude#/57.2958) * COS(latitude/57.2958) * 
				COS(longitude/57.2958 - #target_zip.longitude#/57.2958)))) * 3963) 
				AS distance
			    FROM zips
			    WHERE (latitude >= #target_zip.latitude# - (#ARGUMENTS.radius#/111))
			    AND (latitude <= #target_zip.latitude# + (#ARGUMENTS.radius#/111))
			    AND (longitude >= #target_zip.longitude# - (#ARGUMENTS.radius#/111))
			    AND (longitude <= #target_zip.longitude# + (#ARGUMENTS.radius#/111))
			    ORDER BY distance;
		<cfreturn available_locations>


$(document).ready(function() {
	$('#dealer_locator').submit(function() {
		if($('input[id="zip_code"]').val() != '') {
				type: "POST",
				url: "/resources/cfc/locator.cfc?method=list",
				data: ({ zip: $('input[id="zip_code"]').val(), radius: $('select[id="radius"]').val() }),
					dataType: "xml",
					success: function(xml) {
						//$('#SelectedCities option').remove();
						$(xml).find('record').each(function() {
							$("#SelectedCities").append('<p>' + $(this).find('city').text() + '<\\/p>');
		return false;


		<form action="/resources/cfc/locator.cfc" method="post" id="dealer_locator">
			<!---label for="zip_code">Zip Code</label--->
			<input type="text" name="zip_code" id="zip_code" title="Zip Code" />

			<select name="radius" id="radius">
				<option value="" selected>Select a search radius</option>
				<cfloop from="5" to="100" step="5" index="i">
				<option value="#i#">#i# miles</option>
			<button type="submit">find</button>
			<div id="results_container"></div>

Firebug is reporting a 200 OK response when this fires, but the response tab is empty. ANY help is SO appreciated.


going by that link… i’m getting JSON returned, BUT i’ve still never seen it separated into two different Arrays of Columns and Data.

Also, i changed the JS call to define the datatype in the url string. Got that bit of wisdom from a page on ray camden’s site. Keeps the cfc method generic and lets whatever is consuming the data determine what format it needs.

  1. I agree with downtrodden - you should call the CFC via conventional ColdFusion and dump out the results.
  2. You don’t have the returnformat specified. I think the default is WDDX if not specified. Try adding returnformat=“xml” to the function in question.
  3. Failing the first two points, I would use Fiddler, ServiceCapture, Charles or some equivalent http proxy and inspect the results coming back from the CFC. That should give you some clue as to what is coming back.

I expect those three points will steer you to the solution.

and if I try to access the cfc directly, I get nothing… i thought it was supposed to generate a description of the cfc and all the methods?

yeah, that’s the thing… i’d change the response type if I was getting SOMETHING to look at. I’m getting nothing, blank. :frowning:

Then I’d call the component manually with cfinvoke. Just to see what the results look like.

i thought it was supposed to generate a description of the cfc and all the methods?

Yes, if you’re logged into the admin. Otherwise I think should redirect to the cf admin login screen. The fact that you’re getting blank is strange indeed …

That’s the way ColdFusion returns it’s JSON. It’s not ideal, but it’s how they decided to do it. If you’re returning a straight query it might be better to convert it to an array of structures first. That’ll return it in a more conventional, and familiar, JSON format.

Take a read over this blog post and I think you’ll get some ideas on how to proceed:

I haven’t used that particular snippet myself. But the first thing I’d check is what is the actual content of the response? Second thing, the data type jumps out at me:

  dataType: "xml"

I assume that means the response is supposed to be xml. Is your cfc actually returning xml…?

bmeloche made some good suggestions. I would start there. In particular:

  • Try changing your function’s returnformat. I too suspect it’s returning wddx by default

Okay, i’m getting a response now but it’s spitting out a form of json i haven’t seen before. I’m used to an array of hashes {[name:value, name2:value2],[name:value, name2:value2]} vs this {“COLUMNS”:[“VALUE”,“VALUE2”],“DATA”:[[“VALUE”,“VALUE2”]]} that the CF8 server is spitting out.

What do I even search for to see how to deal with this? I’ve looked up jquery and ‘column’ but all i get back is stuff about editing tables and the like.