简体   繁体   English

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

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

I have a input in my page, which is linked with ajax when I type any name, it searches that name in my database and returns the result as a html form all inputs has the values form database, in that form I place a submit button which is not working. 我的页面中有一个输入,当我键入任何名称时,该输入都与ajax链接,它在我的数据库中搜索该名称,并以html形式返回结果,即所有输入均具有值形式的数据库,在该形式中我放置了一个提交按钮这是行不通的。

My Code: HTML 我的代码: HTML

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

AJAX 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 PAGE 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 is only aware of the elements in the page at the time it runs, so new elements added to the DOM are unrecognized by jQuery. jQuery仅在运行时知道页面中的元素,因此jQuery无法识别添加到DOM中的新元素。 To combat the problem use event delegation , bubbling events from newly added items up to a point in the DOM which was there when jQuery ran on page load. 为了解决该问题,请使用事件委托 ,将事件从新添加的项目冒泡到DOM在jQuery在页面加载时出现的位置。 Many people use document as the place to catch the bubbled event, but it isn't necessary to go all the way up the DOM tree. 许多人将document用作捕获冒泡事件的地方,但是并不需要一直走到DOM树上。 Ideally you should delegate to the nearest parent existing at the time of page load. 理想情况下, 您应该委派给页面加载时存在的最接近的父级。

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

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