I thought I would experiment, write and share a JQuery plugin. I have written simple plugins for applications, but this is a first time for a public release plugin. The plugin is designed to manipulate dates. For any date on the page, you can transform the date to show its real age. To overcome a few huddles, I will explain.
To return JSON from an ASMX service, JQuery can be setup like so:
I have simplified JQuery’s mechanism in the plugin, and by no means you don’t have to use this. However for my case, I wrapped it inside a function for ease. This is how it should be setup to request JSON from an ASMX web service. The web service will see in the request headers JSON is requested, and therefore return JSON. So how do we do this?
You can provide your own mechanism for getting the current date, but this shows how it works.
The plugin has the following options.
InsertMode (optional): – this controls how the age is inserted. (Default value is set to ‘append’).
CustomCompare (optional): – this takes a function to compare dates and return the number of years between them. (Default uses its own compare).
InsertMode consists of the following options.
‘replace’ – replace the date with the real age.
‘append’ – append the date with real age.
‘prepend’ – prepend the date with the real age.
Although the example is a VS project, the JQuery plugin is not .NET specific.