【发布时间】:2013-12-13 00:18:34
【问题描述】:
也许我只是很困惑。我对 AJAX 比较陌生。我在一个页面上有多个表单,我最终尝试提交,但目前,我只想提交单击其提交按钮的特定表单。由于范围问题,我将“选项”和“绑定”带入了我的单个函数,但我也很乐意在它之外工作。这不起作用(尝试根据它与页面上的其他表单共享的表单类来选择表单,但挑选出它的特定 id):
$('.teacher_account_form').submit(function(){
var form_submitted = $(this).attr('id');
console.log(form_submitted);
var options = {
type: 'POST',
url: "/users/p_teacher_account_work",
beforeSubmit: function() {
$('#pay_output').html("Updating...");
},
success: function(response) {
$('#pay_output').html(response);
}
};
// Using the above options, ajax'ify the form
$(form_submitted).ajaxForm(options);
});
以下内容有效,但这意味着我正在对我的表单 ID 进行硬编码以进行绑定:
var options = {
type: 'POST',
url: "/users/p_teacher_account_work",
beforeSubmit: function() {
$('#pay_output').html("Updating...");
},
success: function(response) {
$('#pay_output').html(response);
}
};
// Using the above options, ajax'ify the form
$('#pay_form').ajaxForm(options);
通过工作,我的意思是我的成功消息从 php 文件回显到页面,并且数据库更新。
更新:我使用的是按钮,而不是输入类型 =“提交”
【问题讨论】:
标签: javascript php jquery ajax forms