JQuery ajax页面请求

时间:2010-01-18 07:55:23

标签: jquery

我有一个php日历脚本,使用get vatiables在几个月内移动,例如

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请求更新日历的最佳方法是什么?

是否将实际日历放在单独的页面上并调用类似的内容?

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

            }
         });

帮助/评论赞赏感谢

1 个答案:

答案 0 :(得分: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内容。