2012-02-15 232 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.'); 
     } 
});