If you have found a pretty good javascript control that requires data to be loaded from server asynchronously – XsltDb is something you’d appreciate. It provides a very simple way to load data asynchronously by javascript function or by providing a URL.
Here I provide an example of loading list of Modules currently installed in DotNetNuke.
1. Creating javascript function
The first method covers full cycle of AJAX. XsltDb helps creating javascript function that goes to the server (using XmlHttpRequest) queries database, returns data to client and call a user-defined callback. This is an XsltDb configuration that creates such a function:
<mdo:callable js="getModules(filter)"> <xsl:copy-of select="mdo:sql(' select * from {databaseOwner}[{objectQualifier}desktopModules] where FriendlyName like @filter ', 'module', '@filter', concat('%', mdo:request(filter), '%'))" /> </mdo:callable>
The code is pretty short, isn’t it?
Attention! As we use free sql statement we must check the Super Module option above XSLT Editor.
Resulting output on HTML page is a javascript function getModules that returns a list of modules as XML string. You can use XSL to create any type of output: string, JSON, etc. Usage of the getModules is simple:
Asynchronous
getModules("x", function(result){ alert(result); });
Or synchronous (not recommended)
alert(getModules("x"));
2. Creating a URL handler
Controls often capable of querying a URL that return XML data. This is also easy to implement with XsltDb. Create a new module, click Edit XSLT and fill “Alias” field above the control with “modules” alias name. You also must check Super Module option tobe able to execute SQL.
<xsl:if test=" mdo:request('service')='modules' "> <xsl:copy-of select="mdo:sql(' select * from {databaseOwner}[{objectQualifier}desktopModules] where FriendlyName like @filter ', 'module', '@filter', concat('%', mdo:request(filter), '%'))" /> </xsl:if>
xsl:if is not nesessary and used to prevent output generation when we open a page where the module sits.
The URL that returns data provided by the module is:
/DesktopModules/XsltDb/ws.aspx?service=alias-name[&additional-parameters]
In our case we must use
/DesktopModules/XsltDb/ws.aspx?service=modules&filter=x
Example would be:
$.ajax({ url: '/DesktopModules/XsltDb/ws.aspx?service=modules&filter=x', success: function(data, status, http) { alert(http.responseText); } });
Note that you can put all your services on a separate page and reuse it from any page of your site or from other sites.
More about AJAX in XsltDb:
Nice!! XsltDb is awesome!!
I will use it to create a simple radio database (with filters like music type) and play the MMS URL Streaming using JWPlayer (Silverlight Version which accepts reproducing as an external WMPlayer)
Eduardo,
It would be greate to get a feedback after you try using XsltDb. I understand that it is not fully documented so if in trouble ask me for a help or a new feature.
The best place to do it is http://xsltdb.codeplex.com/Thread/List.aspx