2010-02-08 93 views
0

我想刷新#calendar div与新内容发送到calendar.php
我收到成功警报,但内容不刷新。如何获取新的calendar.php以显示发布的数据?jquery ajax问题与div刷新和新内容

$(document).ready(function(){ 
$('#next').click(function() { 
    $.ajax({ 
     type: "POST", 
     url: "calendar.php", 
     data: 'year=2012', 
     target: '#calendar', 
     success: function(html){ 
      alert("Success"); 

     } 
    }); 
    }); 

相关的HTML代码是在这里: #next是calendar.php上一个div标签的ID

<div id="calendar"> 
    <?php include('calendar.php'); ?> 
</div><!-- /#calendar --> 

回答

2

你可以设置它明确地在你的处理器:

success : function (html) { 
    $('#calendar').html(html); 
} 

此外,由于您将取代日历div的内容(其中包含#next链接),因此您可能需要使用.live('click', function() { inst因为你会失去事件处理程序,所以你需要输入.click(function()

+0

你是一个摇滚明星。谢谢! – kylex 2010-02-08 23:18:59

0

jQuery提供了以下简单的方法:

$('#next').click(function(){ 

    $('#calendar').load('calendar.php', {year: 2012}, function(){ 

     // The response html was loaded into the calendar div already 
     // You could use this area to display a success message 
     alert("Done!"); 

    }); 

});