CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Jay Kimble -- The Dev Theologian

Philosophizing about the .Net religion

Announcing JAAJAX Lib 0.1alpha - An AJAX Library

(AKA trying to get listed on Mike Gunderloy's Daily Grind twice in 1 week).

Believe it or not, I don't hate AJAX.  It's true.  My complaint has always been about best practices being identified (I have yet to find an article on this).  Despite what many of you may think I have been working on an AJAX library for several months.  When Ajax.Net first came out I was disappointed because it seemed to be just like my privately developed library; just recently I discovered some differences.  So...

Announcing Just Another AJAX library (JAAJAX Lib) for .Net
This library is the result of the project that I work on in my current job.  The project is in ASP and ASP.Net.  A former co-worker of mine loved Remote Scripting (old technology for ASP that does exactly what AJAX does).  My co-worker sprinkled remote scripting all over his code (you have heard my complaints here if you are a regular reader).  I have been slowly converting all the old code to ASP.Net.  The problem is that much of the code lies in the client code, so my choices are to re-write from scratch or do something else.  I decided to write my own AJAX library. and try to morph the code a little.  One thing I have seen with a number of AJAX libraries is that they use HTTP Gets which means that the data from javascript is recorded in the server logs.  If your website is used in certain European countries the privacy laws are such that you must hide all personal data... HTTP Gets don't qualify.  My library supports both and it also supports synchronous and asynchronous retrieval.

Notes
I do require that you get the sarissa library which syncs up the XML object model between IE and Mozilla (it may also provide Safari compatibility, but I'm not sure).  Beyond that you need the actual JAAJAX Lib package.  The package is fairly complete, I need to clean up the code a bit (but you will get it).  The package has been built to be easy to use with minimal setup. 

License
??? I have no idea how to release this.  Basically, buyer beware, don't sue me for any damage it causes.  If you find a bug please let me know; if you fix a bug I would like to have the fix, but you're under no such requirement.  You can derive whatever you want from this, and I don't really require an acknowledgements.  Anyone want to tell me what my license is?   I am releasing the under the BSD license. [Thanks, Blair!]

How to use it
1) Reference the JAAJAX_Lib
2) Create a new WebForm and change the page class you inherit from to the PageWithRemoteMethods class.
3) Set the location/URL Path for the _jaajax.js file and the location for the Sarissa libraries (You can also tell the library which parts of Sarissa to load).
Example:
Private Sub Page_Normal_Load() Handles MyBase.After_PWRM_Load
     Me.JAAJAX_CLIENT_LOCATION = Me.TemplateSourceDirectory + "/_script/"
     Me.SARISSA_CLIENT_LOCATION = Me.JAAJAX_CLIENT_LOCATION
End Sub


4) Mark all functions that you want to retrieve a value from with the RemoteCallableAttribute; be sure to look at the RemoteCallable attribute's instantiator, because it gives you options to use either post or get, as well as use synchronous and asynchronous calls.
Example:
<RemoteCallable(True, True, True)> _
Public Function add(ByVal n1 As Integer, ByVal n2 As Integer) As Integer
     Return (n1 + n2)
End Function


5) This will automatically create the functions in the client side (you only have to call them).  If you are going asynchronous the method will actually take one extra parameter at the end (I believe); this last parameter is the function to call with the result as a parameter.  The result is actually an object value with a property for the Return_Value and a property for the Error_Value (message from any exceptions that have been thrown).

There is a single test web project that shows the usage of the library (I'll build a few more as I grow the library).  BTW, it's currently written in VB.Net.  Since I know that some of you have an aversion to VB I'll probably port it to C# (or maybe IronPython...)

The future
So here's what my plans are:
1) Clean up the code (it's awful right now, but I want to release and get feedback)
2) Build a mechanism to put the javascript in a separate source (hide the source of the javascript proxy stuff)
3) Build a mechanism to return an recordset in XML and provide client side mechanism to traverse the XML.
4) Build a Dynamic Select box that retrieves data from an AJAX call (automatically).



Check out Devlicio.us!

This Blog

Syndication

News

CodeBetter.Com Home
Current Threat level
Terror Alert Level