繁体   English   中英

Ajax:PHP:HTML-Submit按钮在Ajax响应中不起作用

[英]Ajax:PHP:HTML-Submit Button not working in ajax response

我的页面中有一个输入,当我键入任何名称时,该输入都与ajax链接,它在我的数据库中搜索该名称,并以html形式返回结果,即所有输入均具有值形式的数据库,在该形式中我放置了一个提交按钮这是行不通的。

我的代码: HTML

<div class="well">
     <input type="text" name="promote_student_txt" id="promote_student_txt" />
     <div  id="rr2"></div>
 </div>

AJAX

$('#promote_student_txt').keyup(function(){
    var email = $('#promote_student_txt').val();
    $.post('includes/promote_student_search.php',{e:email},function(data){
        $('#rr2').html(data);
});
});

PHP页面

 <td>
       $id="FROM DATABASE";
       $class="FROM DATABASE";
       $section="FROM DATABASE";
       <form  method='get' action='new.php'> 
          <input type='hidden' name='student_id' value='$id' /> 
          <input type='hidden' name='old_class' value='$class' />
          <input type='hidden' name='old_section' value='$section'/>
          <input type='submit' name='promote_single'/>
       </form>
    </td>

jQuery仅在运行时知道页面中的元素,因此jQuery无法识别添加到DOM中的新元素。 为了解决该问题,请使用事件委托 ,将事件从新添加的项目冒泡到DOM在jQuery在页面加载时出现的位置。 许多人将document用作捕获冒泡事件的地方,但是并不需要一直走到DOM树上。 理想情况下, 您应该委派给页面加载时存在的最接近的父级。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM