I call this function on a form element, and based on what the json object contains, change the background of a form element. Essentially a simplified validation - but I don't wanna use jQuery's bloated validation plugins.
IV.validSimple ( { obj: '#email', event: 'blur', check: 'emailexists' } ); The problem is (the closure context/scope drives me mad :), how can I pass the d variable (object) to the success callback (_IV.bool) in the code below.
var IV = { urlBase: '/oink/ajax/', validSimple: function(d) { var _IV = this; $(d.obj).bind(d.event, function() { $.ajax ({ url: _IV.urlBase + d.check + '?' + $(d.obj).val(), async: true, dataType: 'json', success: _IV.bool, }); } ); }, bool: function(data) { if (data.ok == 1) $(obj).css('backgroundColor','#c5e8c5'); else { $(obj).css('backgroundColor','#f7c7c7').focus(); } } //function };