I use the $.post function to submit an ajax request as such:
$('.typeAform').submit(function(){
$.post('/home', { somevar : 'somevalue' }, function(){
//do something with the original form
});
return false;
});
I’d like to identify my form after submission from the $.post callback so I can do something with it (i.e. change its background color, delete it, etc…).
Normally, I’d be able to call the form by its unique id that I know ahead of time, but here I don’t have it – I am using a class for the form, not a single id.
Is there a way I can identify the form I just submitted without using a global variable (i.e. pass it to the callback somehow).
Thanks!
EDIT:
Because the target of the
submitevent should always be the form itself, you could also use thetargetproperty of theeventobject, as in:e.targetIf this gives you trouble, then there are other ways to avoid creating a variable if you don’t want that.
Get the ID from the DOM element in the
.submit():So it would be:
Or if you want the form itself, just reference
this.Note that once you’re inside the
$.postcallback,thisno longer references the<form>. That’s why we referenced it in a variable.