0

I try to use a ajax result for a true/false return in a function, but it doesn't work. I have read all about the stuff here so i built the following code:

$( "#toolbox-tabs" ).on( "tabsbeforeactivate", function( event, ui ) {
   validateSession().done(function(r){
     if (r.session)
        return true;
     else
        return false;
   });
});

function validateSession() {
   return $.ajax({
    url: check.php,
    data: {
        session_check : true
    },
    type: 'POST',
    dataType: 'json'
  });
}

check.php is a simple print json_encode(array("session" => true/false)); The problem is that even if r.session is false, the on.function always returns true. Any help would be appreciated!

Kind regards, Matty

Community
  • 1
  • 1
Matty82
  • 67
  • 6

1 Answers1

0

might be your calling function in wrong way try this..,

$( ".selector" ).tabs({
  beforeActivate: function( event, ui ) {}
});

Try this in IF..

if(r.session == true){
    return true;
}else{
    return false;
}
Ajay Makwana
  • 2,330
  • 1
  • 17
  • 32