I have multiple forms on one page and i am submitting them via Ajaxform plugin like this
<td> <form> form1 </form> </td>
<td> <form> form2 </form> </td>
var options = {
target: '.ajaxMessage',
dataType: 'json', // pre-submit callback
success: function(data, statusText, xhr, form){ myResponse(data,form)},
context: { element: this},
cache: false,
delegation: true,
type: 'POST' };
$(".rform").ajaxForm(options);
In mY AjaxSetup , i have this
beforeSend:function(xhr, settings){
$this = settings.context.element;
alert($this);
But its not working , alert says window object
When you are creating options, “this” is referring to window.
Not sure what you want
thisto refer to inbeforeSend, but it would probably be easiest to just set it to a jQuery reference… like so:and for your context object:
Updated after Comment
I see. This isn’t elegant, but you can use the plugin’s
beforeSubmitcallback to set a global variable to the form (which is passed into that callback,) and then access that in yourbeforeSendcallback.It might even be better to just put your code in
beforeSubmitcallback.(this all assumes you’re using this ajaxForm plugin.)
Updated with Example:
Now in your onSend function you can access
$.MyActiveFormBut, I still think you’re better off just doing whatever you were going to do in the
onSendfunction, inbeforeSubmit, unless you need to intervene at that particular point.