簡體   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