簡體   English   中英

Ajax調用后第二次未觸發Document.ready

[英]Document.ready is not fired second time after ajax call

我已經在Php codeignter的視圖中創建了一個按鈕。

視圖

<div id=div_signup>
      <input id="btnRegisterID" name="btnRegister" style="margin-right: 5px;" value="Register" type="button" class="btn btn-success"/>
</div

控制者

  public function register()
    {

        $this->load->view('MAIN\view_Register');

    }

單擊此按鈕后,我將進行ajax調用,成功后,將再次在注冊div中重新綁定同一視圖。 這意味着在第一個事件之后,現在按視圖重新加載了按鈕。

Ajax呼叫:

    $(document).ready(function()
        {

 $("#btnRegisterID").on("click", function()
            {
                     $.ajax({
                type:'POST',
                url:'http://localhost/Voyager/Main/register',
                data:{},
                success:function(){
              $("#div_signup").load('http://localhost/Voyager/Main/register');
                },
                failure:function(){
              alert("nooo"); 
                }             
            });
        });          
});

第一次單擊即可正常運行,ajax調用成功。

但是,在第二次單擊上沒有任何反應。

瀏覽器控制台中沒有錯誤。

有人可以幫忙嗎?

我在這里想念什么嗎?

更新:在ajax調用成功后,我將上面的代碼更改為location.reload()。 仍然無法解決問題。

 success:function(){
              location.reload();
                },

將您的按鈕單擊事件更改為這樣

$(document).on('click', '#btnRegisterID', function () {
// You ajax Code

})

嘗試成功刪除

$("#div_signup").load('http://localhost/Voyager/Main/register');

更換

location.reload();

嘗試使用window.location.reload()而不是location.reload();

在該面板之外單擊按鈕部分地為我工作。

但是,我的體系結構存在問題。 如果沒有完整的頁面刷新以保持數據為最新,則無法部分加載jquery中的視圖。

謝謝你的幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM