These last days I've been working a few hours of my spare time on a idea I had long time ago. It can be summed up in just one sentence: to write a small JavaScript library that added to your Web page (PHP, ASP, ASP.NET...) will enable it to be AJAX-enabled without you needing to write a single line of code.

I thought that it would be more difficult, but the fact is that it's been quite easy to achieve.

Now I can present it for you to freely download the result: AJAXInterceptor 0.5 Beta.

Just by adding this small JavaScript module to the end of your web pages, you get your form's submissions intercepted and, instead of sending request to the server in the usual way, they are done asynchronously and in an AJAX-style smooth way.

As long as it is a client-side library it will work with any server technology: ASP.NET, PHP, JSP, Classic ASP... and even with local HTM files. However I've only tested it against ASP.NET and ASP 3.0 applications (please, drop me a line if you test it with other server technologies).

I've included extensibility so that you can add easily your own progress indicators (several included) and show error messages the way you prefer (by default it shows an alert).

The library works by intercepting the submission of forms. It supports automatically submited forms (with submit buttons or the 'enter' key), and form submissions doing by code calling the submit() method. It respects the possible onsubmit event handlers you may have, so you can make your form validation as usual.

Features summary

• No-code AJAXification of web apps
• Supports any server technology, including ASP.NET, JSP, PHP, ASP 3.0...
• In ASP.NET it supports all kinds of postbacks: direct and by code.
• Works in any modern browser that supports AJAX.
• Supports cross-posting of forms, that is, you can send the information to any web page in the same domain. If all your web pages have AJAXInterceptor included (for example, you include it in your master page or template) you can hace
• Respects your custom onsumit event handlers.
• Supports browser history so that your users can hit the previous button and get the last rendered page.
• Two versions of the module:
    - AJAXInterceptor.js: full commented one. Useful for debugging purposes.
    - AJAXINterceptor_r.js: reduced-size version. It downloads faster as it only is  2.6 kB in size. It's better to use this on production apps.
• Automatically show/hide custom progress indicators.
• Support for cancelling operations.
• Support for custom message displaying.
• Supports any form in your page

Obviously this is not substitute at all of full-fledged APIs like Microsoft's ASP.NET AJAX, PHPLiveX or AJAX.NET, but will let you add AJAX support to your apps in a few seconds and without writing any code. Just give it a try!

In the ZIP you will find teh module, a working sample with ASP.NET and a PDF with the help documentation.

I will be very glad if you drop me a line in case you use AJAXInterceptor in any real-world application or if you enhance it with new features. Just use the 'contact' link in the left side of this page to send me an email.

Download: AJAXInterceptor 0.5 Beta (834 KB) ¡Freeware!

Update: Today (1/16/2008) I've added the project to CodePlex: Next releases and additions (if any) will be added there.

💪🏻 ¿Este post te ha ayudado?, ¿has aprendido algo nuevo?
Pues NO te pido que me invites a un café... Te pido algo más fácil y mucho mejor

Escrito por un humano, no por una IA