2017-04-07 21 views
0

我有一個頁面彈出一個模式,並使用hidden.bs.modal事件,我想通過ajax重新加載相同的頁面內容,即body標籤html。我有以下代碼:Bootstrap模式隱藏事件通過ajax重新加載正文

$("#actions-modal").on('hidden.bs.modal', function(){ 
     alert(document.location) 
     $.ajax({ 
      url: document.location, 
      type: "get", 
      sucess: function(data){ 
       alert('hhhh') 
       return $("#body1").html($(data).find('#body1')); 
      }, 
      error: function(xhr){ 
       console.log(xhr); 
      } 
     }) 
    }) 

在上面的代碼中,alert(document.location)工作正常。但是,在ajax 的錯誤處理程序中,ajax的處理程序successconsole.log(xhr)都不能正常工作。即沒有successerror!另外,瀏覽器控制檯中沒有任何錯誤。

回答

0

document.location會返回你的對象,所以請嘗試使用document.location.href這將返回你的URL的字符串。然後AJAX調用將開始工作。

0

從您的成功功能中刪除return。更改元素的html時不需要返回。只有在做這樣的事情時才需要退貨:

function getHTML() 
{ 
    $.ajax({ 
      url: document.location, 
      type: "get", 
      sucess: function(data){ 
       return data; 
      }, 
      error: function(xhr){ 
       return "Failed"; 
      } 
    }); 
} 

var myHTML = getHTML(); 
$('#body1').html(myHTML); 

但是,當您立即設置html時,您並不需要它。

相關問題