Servage Magazine

Information about YOUR hosting company – where we give you a clear picture of what we think and do!

Archive for September, 2012

jQuery Ajax plugin for form submits and links

Sunday, September 2nd, 2012 by Servage
jQuery offers many cool things, but sometimes you like to take the functionality and suit it just a little better or make it just a little more specific to what you need. For example AJAX calls is something which could be standardzied accross your website or app. Why write the same jQuery code all over, of you could create a plugin you attach to every element you want to have the AJAX functionality like this: $('form').MyAjax(); This attaches the MyAjax plugin to all your forms, for example. The code below is suitable for forms and links: function MyAjax (el, options){ var t = this; t.el = el; t.$el = $(el); t.defaultOptions = { url: '/', type: ...