2010-01-18 114 views
1

我有一个php日历脚本,通过使用get vatiables来移动数月。jQuery ajax页面请求

if(isset($_GET['chm'])) : 
$m = ($_GET['prm'])+($_GET['chm']); 
else: 
$m = date("m"); 
$y = date("Y"); // Find today's year 
endif; 
$d= date("d"); // Find today's date 
$y= date("Y"); // Find today's year 
$no_of_days = date('t',mktime(0,0,0,$m,1,$y)); // This is to calculate number of days in a month 
$mn=date('F',mktime(0,0,0,$m,1,$y)); // Month is calculated to display at the top of the calendar 
$yn=date('Y',mktime(0,0,0,$m,1,$y)); // Year is calculated to display at the top of the calendar 
$j= date('w',mktime(0,0,0,$m,1,$y)); // This will calculate the week day of the first day of the month 

日历显示的索引页,什么是使用一个jQuery Ajax请求更新,而不需要页面refersh的calendat的最佳方式?

它是把实际的日历放在一个单独的页面上,并调用这样的东西?

var prm = $("#prm"); 
var chm = $("#chm"); 
$.ajax({type: "GET", url: "calendar.php", data: "&prm=" + prm + "&chm=" + chm, 
      complete: function(data){ 
       calendardiv.html(data.responseText); 

      } 
     }); 

帮助/评论赞赏adavance

+0

嘿,欢迎来到Stack Overflow!只是查看你的问题清单,并想确保你知道将答案标记为已接受是多么重要。在其他问题上,您可以通过点击正确答案旁边的灰色检查来做到这一点。它的堆栈溢出方式奖励正确回答你的问题的人。 – 2010-01-18 08:13:15

回答

2

使用辅助方法由于在那里你可以帮助简化事情。在这种情况下,load

// I assume you have this up farther in your code 
// since it wasn't in the code you posted: 
var calendardiv = $("#calendar"); 

var prm = $("#prm"); 
var chm = $("#chm"); 

calendardiv.load('calendar.php', { prm: prm.val(), chm: chm.val() }); 

本示例假定prmchminput元件。如果它们是正常的HTML元素,则使用prm.text()chm.text()而不是prm.val()chm.val()

load发送GET请求一个页面,通过该键/值对作为一个正常的查询字符串(即你没有建立像'&key=' + value),然后替换返回值的html内容元素。