Currently most of my extra time has been busy developing a pretty cool site which I hope to share with you in the near future. During the development process I have learned some new things, and came across new problems.
One of those problems came in the form of trying to post a web form to the server using JSON and AJAX. As I first started coding the site it was decided that these form pages would live on pages by themselves and that the user would interact with them just like any other form on the internet. When the form is submitted the page refreshes and sends the data to the server and receives data back from the server if needed.
About halfway way through the development we decided to change the way the forms work. Instead of the forms living on pages by themselves we decided that they should be loaded with AJAX. This meant that the form would load dynamically, and didn't rely on a page refresh; making it better for the user. Unfortunately this also meant that my code needed to change as well to handle the data in a new way.
Using JSON as the data type meant that I would have to explicitly set the key/value pairs in the JSON string to send in the AJAX call. I didn't particularly want to do this because, while it is easy for login forms that only have two fields in the form, it makes it more tedious for forms that have 20 fields.
Me being lazy, I decided to make a jQuery plugin to handle the data in the form fields and construct a JSON object automatically to be passed in the AJAX call. I sat down and coded this plugin in an hour, and it got the job done nice and efficiently.
What's The Big Deal?
It's not a big deal. Other than the fact that this is the first jQuery plugin that I decided to release to the public. I came from a design background, so when I first started learning jQuery 5 years ago I was really unsure of my code. Was it good enough? Was it up to standards? Today I am making this plugin public because I am transitioning into a backend developer, and I have come to the realization that my code won't get any better if there is no one to critique it. Also who knows? It may help someone along the way too.