2012-02-15 230 views
0

我只是想用ajax加載一個簡單的html頁面。jquery ajax內容未加載

$("h1").click(function() { 
    $.ajax({ 
    type: 'POST', 
    url: 'ajax.html', 
    success: function(response) { 
      $('#buttonGroups').html(response); 
      alert('Load was performed.'); 
     } 
    }); 
}) 

但我從來沒有得到警報..?我錯過了什麼?

+4

難道它擊中了服務器?請求是否成功?你沒有提供太多你知道的信息。 – gdoron 2012-02-15 17:22:21

+0

對不起。是的,它獲得了200的狀態,它清除該元素的內容.. – Mackelito 2012-02-15 17:30:42

+3

剛剛解決它..我錯過了「dataType:'html',」:) – Mackelito 2012-02-15 17:31:03

回答

1

您使用的是響應爲HTML,所以你需要告訴jQuery的:

$("h1").click(function() { 
    $.ajax({ 
    type: 'POST', 
    url: 'ajax.html', 
    dataType: "html", // <==== 
    success: function(response) { 
      $('#buttonGroups').html(response); 
      alert('Load was performed.'); 
     } 
});