Posted by Cliff Pearson (Guest)
on 16.03.2006 19:28
Hi all.

I'm attemting to get the Rolodex demo working on a CF MX 6.1 server, 
which will hopfully form the basis of a staff database I've been asked 
to add to a client's intranet.

I've customised the demo code as follows:
-------------------------------------------------
<script>
   onloads.push( registerAjaxStuff );
   function registerAjaxStuff() {
      ajaxEngine.registerRequest( 'getPersonInfo', 'ajax_directory.cfm' 
);
      ajaxEngine.registerAjaxElement( 'personInfo' );
   }
   function getPersonInfo(UserID) {
      ajaxEngine.sendRequest( 'getPersonInfo', "UserID=" + UserID );
   }
</script>

<table cellspacing="5" cellpadding="5">
	<tr><td valign="top">
		<select id="listBox" size="10" onchange="getPersonInfo(this.value)" 
style="font-family:arial;font-size:11px;display:inline;border:1px solid 
red">
			<cfoutput query="GetDirectory">
				<option value="#UserID#">#Firstname# #Lastname#</option>
			</cfoutput>
		</select>
		</td>
		<td>
			<div style="display:inline" id="personInfo">
				Select a name to the left to see the AJAX rolodex entry for the 
selected person.
			</div>
		</td></tr>
</table>
-------------------------------------------------
So clicking on an entry in the select field should call 
'ajax_directory.cfm?UserID=n', which uses <cfxml> to return an XML 
packet.  Calling this page manually seems to work ok.

The 'getPersonInfo' function is being called, but is stalling.  If I add 
'alert(UserID);' before the 'ajaxEngine.sendRequest' line, I get an 
alert box with the ID number.  If I place the alert after that line, I 
don't get an alert at all.

Can anyone see what I'm doing wrong?

Regards

</cliff>
Posted by Ross Lawley
on 16.03.2006 20:57
Hi Cliff,

OK, not sure whats happening - two obvious things spring to mind:

A javascript error / or the old classic - the xml being sent with out 
XML headers.

Are there any javascript errors (checkout the excellent firebug firefox 
extension) ?

Test that the output is valid xml (load the url in firefox and make sure 
the xml is displayed).

Failing that can you post some code that replicates it ;)

Ross
Posted by Jared Armstrong
on 16.03.2006 22:53
Do you have <CFCONTENT TYPE="text/xml"> at the top of your page that 
creates the xml document?
Posted by Cliff Pearson (Guest)
on 17.03.2006 01:39
Hi Ross.

Thanks for the reply and for the tip about FireBug - an excellent 
addition to the toolbox!  B->

There was an odd error - Prototype.js wasn't loading properly if loading 
locally, but works if I link to 
http://www.openrico.org/javascripts/prototype.js - I'll sort that one 
out later.

It now does call the action page properly (the last line of the code 
below logs the parameters passed to the page each time it's called), but 
the returned XML packet isn't having any effect on the calling page. 
This is the CF page that generates the XML packet - fairly 
straight-forward:
-------------------------------------------------
<cfquery name="GetDirectoryEntry" datasource="Zingaro">
	SELECT * FROM Directory
	WHERE UserID = #URL.UserID#
</cfquery>

<cfoutput query="GetDirectoryEntry">
	<cfxml variable="Directory">
		<ajax-response>
			<response type="element" id="personInfo">
				<div class="person">
					<span class="personName">#FirstName# #LastName#</span>
					<span class="personDept">#Department#</span>
					<span class="personEmail">#Email#</span>
					<span class="personPhone">Phone: #TelExtn#</span>
					<span class="personMobile">Mobile: #Mobile#</span>
				</div>
			</response>
		</ajax-response>
	</cfxml>
</cfoutput>

<cfcontent type="text/plain" 
reset="yes"><cfoutput>#ToString(Directory)#</cfoutput>

<CF_Log TEXT="#cgi.QUERY_STRING#">
-------------------------------------------------
If I call the page directly, I get the following:
-------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<ajax-response>
			<response type="element" id="personInfo">
				<div class="person">
					<span class="personName">Cliff Pearson</span>
					<span class="personDept">CAP Communications</span>
					<span class="personEmail">cliff@capcomms.net</span>
					<span class="personPhone">Phone: 123</span>
					<span class="personMobile">Mobile: 123</span>
				</div>
			</response>
		</ajax-response>
-------------------------------------------------

I see no JS errors when the initial page loads and FireBug shows me the 
response text being returned, but I get an error: 'request.responseXML 
has no properties', which refers to line 474 of Rico.js, which reads: 
'var response = 
request.responseXML.getElementsByTagName("ajax-response");'.

The response text reported by FireBug is the same as the example above, 
but no update.

Any ideas, folks?

TIA

</cliff>
Posted by Cliff Pearson (Guest)
on 17.03.2006 01:45
Jared Armstrong wrote:
> Do you have <CFCONTENT TYPE="text/xml"> at the top of your page that 
> creates the xml document?

By George, he's cracked it!  B->

Thanks for the tip - I was using text/plain, as per the example on 
creating an XML packet from the Advanced CF MX Application Development 
book - that's the first time a Ben Forta book has let me down.

Makes me wish I'd checked the forum again before posting that last tome.

Many, many thanks

</cliff>
Posted by Jared Armstrong
on 17.03.2006 12:54
Glad to hear you got it working.

-Jared
Posted by Debbie Collins
on 06.07.2007 14:38
I am having the same problem ... I can see the results but they don't 
display.. my code that produces the xml results is this:

I am very new at this and would greatly appreciate any help as this is 
something I need to have for an application Im now working on... thanks 
in advance

<cfquery name="GetDirectoryEntry" datasource="cfdocexamples">
	SELECT * FROM Employees
	WHERE Emp_ID = #URL.UserID#
</cfquery>


<cfoutput query="GetDirectoryEntry">
	<cfxml variable="Directory">
		<ajax-response>
			<response type="element" id="personinfo">
				<div class="person">
					<span class="personName">#FirstName# #LastName#</span>
					<span class="personDept">#Department#</span>
					<span class="personPhone">Phone: #Phone#</span>

					</div>
			</response>
		</ajax-response>
	</cfxml>
</cfoutput>
<CFCONTENT TYPE="text/xml">
<cfoutput>#ToString(Directory)#</cfoutput>