• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 506
  • Last Modified:

Converting a mysql query to xml for spry or ajax in Coldfusion

Hi Experts!

I have a grip on CF and MySQL.  I don't have a grip on XML.

I need to go from a mysql query to spry or ajax.  Is it even possible to do?  Am I doomed?
0
ImWorkingOnItNow
Asked:
ImWorkingOnItNow
  • 5
  • 3
2 Solutions
 
cfEngineersCommented:
0
 
ImWorkingOnItNowAuthor Commented:
It certainly does.  Thanks for posting.

Would that be an xml file or a cfm file?
0
 
_agx_Commented:
XML is totally different than ajax / older spry (both javascript).  What exactly do you need to do?
0
Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

 
ImWorkingOnItNowAuthor Commented:
Hi _aqx_!

Right now, all I need to do is create a dynamic table and a "check for availability" button for a login form.  I've always been curious about how to get from mysql to xml.
0
 
_agx_Commented:
You don't have to tie yourself to spry specifically.  There's lots of different implementations.  Binding, jquery, etc..  All you need is a javascript/ajax call to send info to a CFC (or .cfm page). Then parse the response returned from the CFC.

Here's an example using CF/jquery
http://stackoverflow.com/questions/2287746/extjs-jquery-script-to-check-username-and-email-
availability/2298809#2298809

Another using bindings
http://www.experts-exchange.com/Software/Server_Software/Web_Servers/ColdFusion/Q_25214256.html

There's also bunches of examples in the docs, like this one
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WSc3ff6d0ea77859461172e0811cbec22c24-7a01.html#WSc3ff6d0ea77859461172e0811cbec10aa6-7ff0

Form
<cfajaximport> 
<script> 
    function submitForm() { 
        ColdFusion.Ajax.submitForm(
        	'loginForm', 
        	'MyComponent.cfc?method=checkAvailability', 
        	onCompleteHandler, 
        	onErrorHandler); 
    } 
     
    function onCompleteHandler(text) { 
    	var result = ColdFusion.JSON.decode(text);
    	if (!result.isAvailable) {
        	alert("Sorry! The name "+ result.loginName +" is already in use"); 
    	}
    	else {
        	alert("The name "+ result.loginName +" is available!"); 
    	}
    } 
     
    function onErrorHandler(code, msg) { 
        alert("Error!!! " + code + ": " + msg); 
    } 
</script> 
</head> 
<body> 
 <form name="loginForm"> 
    login <input type="text" name="loginName" value="John"> 
</form> 
 <a href="javascript:submitForm()">Submit form</a> 
</body> 
</html>

Open in new window



MyComponent.cfc
<cfcomponent>
    <cffunction name="checkAvailability" access="remote" output="false" returntype="struct" returnformat="json">
        <cfargument name="loginName" type="string" required="false">
		<cfset var result = {}>
		<cfset result["isAvailable"] = true >
		<cfset result["loginName"] 	 = arguments.loginName >

		<!--- for testing, name "john" is already in use --->
		<cfif arguments.loginName eq "john">       
			<cfset result["isAvailable"] = false >
		</cfif>
		
        <cfreturn result>
    </cffunction>
</cfcomponent>

Open in new window

0
 
_agx_Commented:
I've always been curious about how to get from mysql to xml.

Technically you don't need xml for this type of task.  JSON format works just as well.
0
 
ImWorkingOnItNowAuthor Commented:
Is there ever a reason to do this?
0
 
_agx_Commented:
Not sure I follow.  There are reasons to do most things if you search hard enough ;-) But usually it's the other way around: ie I am faced with problem "XYZ", what techniques will help me solve it?

0
 
_agx_Commented:
.. in other words, are you asking generally "how would I convert query results to XML"  OR is it a specific problem you're trying to solve like:  create a "check for availability" button for a login form?  
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now