ajax td 替换后提交时表单缺少元素
我有一个学区下拉菜单,其中包含一个与之相关的 onchange 事件。当它发生变化时,我会执行 ajax 调用来获取该地区的学校列表。 ajax 页面上的 html 具有每个学校的复选框,因此可以将某人分配到单个学区下的多个学校。 ajax 工作正常,我修改了具有特定 id 的 td 元素的 html,并且学校名称及其复选框正确显示。我检查了其中一些,然后提交了表单,但令我沮丧的是,我用 ajax 添加的输入标签(复选框)都没有出现在表单中。我已经检查了其中一些,因此表单字段不应在提交中出现为空。
我使用 $('#formID').serialize();
来检查表单是否有输入,但它说没有。然后我使用 $('input[name=SchoolID]').each(function(){alert(this.value);}) 打印出复选框的值,这确实有效。
我在这里错过了什么吗?我是否需要以某种方式重新加载表单以包含新的输入字段?为什么我的输入字段没有出现在表单提交中?
function getSchools(userID){
var districtID = $('#DistrictID').val();
$.get('ajax/ajaxSchools.cfm',
{
UserID: userID,
DistrictID: districtID
},
function(data){
var schoolTd = $('#school-td');
//schoolTd.html("");
//schoolTd.append(data);
schoolTd.replaceWith(data);
}
);
}
I have a school district drop down with an onchange event tied to it. When it changes, then I do an ajax call to get a list of schools that are in that district. The html on the ajax page has checkboxes for each school so someone could be assigned to multiple schools under a single district. The ajax works fine and I modify the html of a td element with a specific id and the school names and their checkboxes appear correctly. I check a few of them and then submit the form, but to my dismay none of the input tags (checkboxes) that I added with the ajax come across in the form. I've checked some of them so the form field shouldn't come across empty in the submit.
I used $('#formID').serialize();
to check if the form has the inputs, but it says it doesn't. Then I use $('input[name=SchoolID]').each(function(){alert(this.value);})
to print out the values of the checkboxes and that does work.
Am I missing something here? Do I need to reload the form somehow to include the new input fields? Why aren't my input fields coming across in the form submit?
function getSchools(userID){
var districtID = $('#DistrictID').val();
$.get('ajax/ajaxSchools.cfm',
{
UserID: userID,
DistrictID: districtID
},
function(data){
var schoolTd = $('#school-td');
//schoolTd.html("");
//schoolTd.append(data);
schoolTd.replaceWith(data);
}
);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对不起。表单标签围绕 tr 标签而不是 tds 或表格。当我改变它的工作原理时。
Sorry. The form tag was around tr tags instead of tds or tables. When I changed that it works.