tags:

views:

56

answers:

1

I have a php calendar script that moves through the months using get vatiables e.g.

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

The calendar is displayed on the index page, what is the best way to use a JQuery Ajax request to update the calendat without a page refersh?

Is it to put the actual calendar on a separate page and call something like this?

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

            }
         });

Help / comments appreciated thanks in adavance

+1  A: 

Use the helper methods where you can to help simplify things. In this case, 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() });

This example assumes prm and chm were input elements. If they are normal HTML elements, than use prm.text() and chm.text() instead of prm.val() and chm.val().

load sends a GET request to a page, passing the key/value pair as a normal query string (i.e. you don't have to build it like '&key=' + value) and then replaces the html content of the element with the return value.

Doug Neiner