开发者

jQuery Ajax Form Data

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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜