php - jquery - how to create condition in success function -


i want create jquery ajax success function based resp logout.php. if users not sign in,it redirect bring them login page.,but it's not working i'm expected,no event occur when user logged or not.so, wrong ajax function?



logout.php

<?php     if( !$user->is_logged ) {         echo 'true';     }else{         echo 'false';     } ?> 

jquery function in index.html

$(function(){   $.ajax({     type: 'get',     url: "logout.php",      success: function(resp){       if(resp =='true'){         document.location = '../login_test.html';       }       if(resp=='false'){          alert('u logged');         }                }   }); }); 

change errors , made better view:

php:

<?php   header('content-type: application/json');   if( !$user->is_logged ) {         echo json_encode(array('status' => 'ok'));   }else{         echo json_encode(array('status' => 'bad'));   } ?> 

javascript:

$(function(){   $.ajax({     type: 'get',     url: "logout.php",      success: function(resp){       var state = json.parse(resp).status       if(state == 'ok'){         document.location.href = '/login_test.html';       }       else{          alert('u logged');       }                }   }); }); 

if have no alert, , have no redirect - have not .success callback, , problem 1 level above condition. in case show errors js-dev-console browser.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -