jQuery Ajax表单数据 [英] jQuery Ajax Form Data

查看:76
本文介绍了jQuery Ajax表单数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Ajax表单.我正在获取表格的ID.当我的ajax调用成功时.我想通过此ID表单BeforeSubmit才能成功.这样我就可以将结果附加到我想要的地方.

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.

这是代码

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');

我还注意到您正在使用 jquery表单插件,并且仍在订阅.submit不必要的形式的事件:

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

这篇关于jQuery Ajax表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆