I am using a javascript var to control the running of an ajax call. The call is triggered from a click event (on "#week_tag
" div)and only needs to be run once per page load. The same click event also toggles the display of the sliding pane ("#week_summary") where the data from the ajax call is shown.
In the example below, I'm trying to use a variable and an if statement to prohibit the ajax call from being called when the user clicks the "#week_tag
" div a second time to close the sliding pane. The var status is set to "before" when the page is loaded, and set to "after" once the ajax call is made. If the var status is equal to "before", the call is run, else the "#week_summary" is just toggled. It isn't working because I don't know how to give the var "status" a second value of "after". Any ideas?
$(document).ready(function(){
var status = "before";
alert("before:"+status);
$('#week_tag').click(function(){
if(status =="before"){
alert("afterclick:"+status);
var form_date_set = $("input[name='date_set']").val();
$.post("/tortus/index.php/daylog/build_summary",
{date_set:form_date_set},
function(html){
$("#week_summary").html(html);
var status = "after";
});
}
$('#week_summary').toggle('blind');
alert("after:"+status);
});
});