I have an Ajax form. i am caputuring the ID of the form. and when i the ajax call is a success. i want to pass this Id form BeforeSubmit to success. so that i can append the results to a place where i want.
here is the code
function StatusComments() {
$('.status-comment').submit(function() {
$(this).ajaxSubmit(options);
return false;
});
var options = {
beforeSubmit: showRequest,
success: showResponse,
resetForm: true
};
function showRequest(formData, jqForm, options) {
var formID = $(this).attr("id");
}
function showResponse开发者_开发技巧(responseText, statusText, xhr, $form) {
alert(responseText);
var formID = $(this).attr("id");
alert(formID);
}
}
The form is passed as argument to the success handler:
var formID = $form.attr('id');
Also I notice that you are using the jquery form plugin and still subscribing to the .submit
event of the form which is not necessary:
$(function() {
var options = {
beforeSubmit: showRequest,
success: showResponse,
resetForm: true
};
$('.status-comment').ajaxForm(options);
});
function showRequest(formData, jqForm, options) {
}
function showResponse(responseText, statusText, xhr, form) {
var formID = form.attr('id');
alert(formID);
}
精彩评论