Reputation: 54949
I am trying to use Ajax Form Submit. In the BeforeSubmit function. i want to get the id of the form thats being submited.
function StatusComments() {
$('.status-comment').submit(function() {
$(this).ajaxSubmit(options);
return false;
});
//$('.status-comment').ajaxForm(options);
var options = {
beforeSubmit: showRequest,
success: showResponse,
resetForm: true
};
function showRequest(formData, jqForm, options) {
var formID = $(this).attr("id");
alert(formID);
$('.comment'+formID).attr('disabled', true);
}
function showResponse(responseText, statusText, xhr, form) {
var formID = form.attr('id');
$("#commentbox-"+formID).before(responseText);
}
}
but i get formID as undefined in showRequest :(
Upvotes: 1
Views: 9737
Reputation: 1074555
The documentation for the plug-in says that the form instance will be in your jqForm
argument (and already be a jQuery instance), not this
. So:
function showRequest(formData, jqForm, options) {
var formID = jqForm.attr("id"); // <== Change on this line
alert(formID);
$('.comment'+formID).attr('disabled', true);
}
This is not how jQuery-style callbacks normally work, hence your confusion, but that's what the docs say.
Upvotes: 4