使用jQuery插件ajaxForm获取表单ID并上传进度条 [英] Get form id using jQuery plugin ajaxForm and upload progress bar

查看:295
本文介绍了使用jQuery插件ajaxForm获取表单ID并上传进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一页上有几种表单,这些表单是使用ajaxForm提交的,并显示了上传进度.每个表单具有相同的类'.input_form',唯一的ID,以及一个隐藏的输入字段,其名称和类的'category'具有唯一的值. 这是原始示例: http://jquery.malsup.com/form/progress.html

I have several forms on one page which are submitted using ajaxForm and show upload progress. Each form has the same class '.input_form', a unique id, and a hidden input field with name and class of 'category' with a unique value. Here is the original example: http://jquery.malsup.com/form/progress.html

    var bar = $('.bar');
var percent = $('.percent');
var status = $('#status');

$('.input_form').ajaxForm({
    beforeSend: function() {
        status.empty();
        var percentVal = '0%';
        bar.width(percentVal)
        percent.html(percentVal);
    },
    uploadProgress: function(event, position, total, percentComplete) {
        var percentVal = percentComplete + '%';
        bar.width(percentVal)
        percent.html(percentVal);
    },
    complete: function(xhr) {
        status.html(xhr.responseText);
        $('#activity_feed_load').load(querybuild());
        $('.wall_cat_selected').removeClass('wall_cat_selected');
        $('.input_form, .arrow').hide();
        var percentVal = '0%';
        bar.width(percentVal)
        percent.html(percentVal);
        $('.input_form').resetForm();
    }
});     

在完成功能中,我想检索已提交表单的ID或已提交表单中隐藏字段的值.我尝试了以下无效的方法.

In the complete function, I'd like to retrieve the id of the form submitted or the value of the hidden field in the submitted form. I tried the following which didn't work.

var value = $('.input_form .category').fieldValue(); alert('The category is: ' + value[0]); 

基本上,我不确定如何检索($ this)提交的表单.

Basically, I'm not sure how to retrive ($this) for the form submitted.

感谢您的帮助!

好吧,我刚刚从此处的一个相关SO问题中找到了解决方法:

Ok, I just found out how to do this from a related SO question here:

如何在jquery ajaxform插件中使用$(this)

基本上,我只需要在ajaxForm函数中添加以下内容:

Basically, I just needed to add the following to my ajaxForm function:

success: function(html, status, xhr, myForm) {   
        alert(myForm.attr('id'));

    }

希望这对其他人有帮助.

Hope this helps someone else.

推荐答案

好吧,我刚刚从此处的一个相关SO问题中找到了解决方法:

Ok, I just found out how to do this from a related SO question here:

如何在jquery ajaxform插件中使用$(this)

how to use $(this) in jquery ajaxform plugin

基本上,我只需要在ajaxForm函数中添加以下内容:

Basically, I just needed to add the following to my ajaxForm function:

success: function(html, status, xhr, myForm) {   
        alert(myForm.attr('id'));

    }

希望这对其他人有帮助.

Hope this helps someone else.

这篇关于使用jQuery插件ajaxForm获取表单ID并上传进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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