Php 如何使jquery脚本适用于新生成的表单
我有一个脚本,在单击响应时显示表单Php 如何使jquery脚本适用于新生成的表单,php,jquery,ajax,Php,Jquery,Ajax,我有一个脚本,在单击响应时显示表单 $(".table th .glyphicon-edit").one('click', function(){ var $this = $(this); var sectionName = $(this).attr('data-sectioname'); var courseId = $(this).attr('data-courseid'); var sectionId = $(this).at
$(".table th .glyphicon-edit").one('click', function(){
var $this = $(this);
var sectionName = $(this).attr('data-sectioname');
var courseId = $(this).attr('data-courseid');
var sectionId = $(this).attr('data-sectionid');
$.get('/edit_section', { section: sectionName, id: courseId, sectionid: sectionId}, function(response) {
$this.closest('thead tr').after(response);
});
});
“编辑部分”页面
它只显示包含json数据的新页面,但希望在不重新加载的情况下在同一页面上显示此数据。委托您的提交方法。它将处理动态添加的元素
$(document).on('submit','#edit',function(){
// code
});
我编辑了我的脚本,现在它看起来像是$(文档).on('submit','#edit',function(){$('#edit input[type=submit]').submit(function(e){e.preventDefault();var sectionName=$('input#section#u name').val();var sectionId=$('input[name=sectionId]).val();$.ajax({type:'POST',cache:false,dataType:'JSON',url:'/managecourse/update',data:$('#edit').serialize(),success:function(data){console.log(data);},},},});});但它仍然加载新页面发现了问题,我不需要将$('#edit input[type=submit]').submit(函数(e)放入$(document中)。on('submit','#edit',function(){谢谢您的帮助!!!
$('#edit').submit(function(e) {
e.preventDefault();
var sectionName = $('input#section_name').val();
var sectionId = $('input[name=sectionid]').val();
$.ajax({
type: 'POST',
cache: false,
dataType: 'JSON',
url: '/managecourse/update',
data: $('#edit').serialize(),
success:function(data){
console.log(data);
},
});
});
$(document).on('submit','#edit',function(){
// code
});