php - Basic ajax get request -


i'm making calendar 2 links, 1 go month , other go forward month.

this cal.php file:

<div class='cal_wrapper' id='cal'>  <?php    echo "<a href='cal.php?month=m&year=y'>prev month</a>";    echo "<a href='cal.php?month=m&year=y'>next month</a>";     echo $calendar;   ?>  </div> 

what i'm trying use jquery/ajax update what's inside cal_wrapper div without having refresh page. i've hard can't find examples of getting done without using html form. how can send 2 variables through request, month , year, should pretty basic..but i'm going cross eyed trying find on internets..

first give link classes

echo "<a class='month_selector' href='cal.php?month=m&year=y'>prev month</a>"; echo "<a class='month_selector' href='cal.php?month=m&year=y'>next month</a>"; 

then load contents of ajax request wrapper div whenever 1 of links has been clicked.

$('#cal_wrapper a.month_selector').live(function(e){      $('#cal_wrapper').load( $(this).attr('href') );       e.preventdefault();  });  

edit can use .load load page fragments using #wrapper_div

$('#cal_wrapper a.month_selector').live('click', function(e){      $('#cal_wrapper').load( $(this).attr('href') + ' #wrapper_div' );       e.preventdefault();  });  

so wrap cal_wrapper div in #wrapper_div , code above load contents of wrapper div. use live instead of click since dynamically inserting links.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -