2016-07-07 134 views
4

如何在ajax請求後刷新或重新加載div?我有這樣的代碼:在ajax請求後重新加載div

function Register(event) { 
event.preventDefault(); 
    console.log(event); 
    $.ajax({ 
     type: 'POST', 
     url: register, 
     data: { 
      name: $('#name').val(), 
      email: $('#Email').val(), 
      password: $('#password').val(), 
      _token: $('#token').val() 
     }, 
     dataType : "json", 

     success: function (data) { 
      if (data.success){ 

      $('#header'). 
       $('#Register').modal('hide'); 

      } 
     } 
    }); 

} 

我需要重新加載或刷新標題div。

+0

什麼意思是重新加載?它是一種形式嗎? –

+0

你能告訴我們你的'view'或'html'嗎? –

+0

可能重複[ajax成功重新加載div內容不工作](http://stackoverflow.com/questions/21403402/ajax-success-reload-div-content-not-working) –

回答

6

可以DIVID (" #divid");

if (data.success){ 
    $("#divid").load(" #divid"); 
    } 
+1

簡單而甜美。 – claudios

0

我認爲你正試圖重新加載登錄後的標題部分顯示的用戶名之前加載像this.Please記格的空間,註銷等 要做到這一點你必須使用類似的json編碼將你的ajax方法中的所有html返回到「data.success」變量中。

your ajax method function() { 
    $response = array('success' => 'Your html data come here'); 
    echo json_encode($response); 
    exit(0); 
} 
+0

我只想重新加載。用戶名等我使用php進行展示。 –

+0

和ajax調用 成功:函數(數據){(data.success){0128}。 } } –