2017-06-30 120 views
0
function update(){ 

      var name= document.getElementById("TextBox").value; 

$.ajax({ 
          url: '....', 
          type: 'post',        
          data: {....//many data include// 'name' : name, ....}, 

          success: function(data) { 

          var replacevalue=data.replace(/[\[\]']/g,''); 
          alert(replacevalue); 

          var stringstatus=replacevalue.replace(/['"]+/g, ''); 
          alert(stringstatus);         

          if(stringstatus == "success"){ 
           alert ("Successfully Update ")                   
          } 

          else{ 
            alert("Failed!"); 
            return ; 
          } 

          returnToDisplayPage(); 


         },        

          error: function(xhr, desc, err) { 
          console.log(xhr); 
          console.log("Details: " + desc + "\nError:" + err); 
          } 
       }); 


    } 

    function returnToDisplayPage(){ 
     var id = document.getElementById("TextBox").text; 
     window.location = './DisplayPage.php?Name='+id; 

    } 

請推薦我。點擊更新按鈕並刷新或重新加載頁面時,我應該如何獲取更新的數據?在函數returnToDisplayPage()方法中。我只有更新數據的名稱和其他相關領域的數據沒有回來。如何刷新頁面更新數據時點擊更新按鈕

+0

簡單重裝在阿賈克斯成功功能的頁面類似這樣的窗口.location.reload(); – JYoThI

+0

@JYoThI,我嘗試了嘗試,但它並沒有奏效。 –

+0

你可以在應用程序中使用Jquery嗎?如果你可以,那麼在調用函數時,你可以只加載特定的div。 –

回答

0

嘗試是這樣的:

$.post('url', {params}, function(response){ 
    //Here you check if you got response from url 
    // And then you can do whatever you like to do with received data 
    if(response == 'ok'){ 
    //do your stuff 
    //then 
    window.location.reload(); 
    } 
} 
0

當我們將獲得導致響應5秒鐘後頁面會刷新..

success: function(data){ 
    if(data.success == true){ // if true (1) 
     setTimeout(function(){// wait for 5 secs(2) 
      location.reload(); // then reload the page.(3) 
     }, 5000); 
    } 
} 
+0

請儘量避免將代碼轉儲爲答案,並嘗試解釋它的作用和原因。對於那些沒有相關編碼經驗的人來說,你的代碼可能並不明顯。請編輯你的答案,包括[澄清,上下文,並嘗試提到你的答案中的任何限制,假設或簡化。](https://stackoverflow.com/help/how-to-answer) – Frits

+0

當我們將得到響應結果然後5秒後頁面將被刷新... –