title: Why is facebook javascript login code causing endless loop?
body: <p>When I run this code the login pop up and my console logs start to run in an endless loop. I'm not sure if I'm using the FB.login() method right. On the condition that the user arrives at my app connected, I want to prompt for permissions, if they are granted, won't that return a 'connected' status that I should be checking for and handling if it is declined?  </p>
  
  <pre><code> FB.Event.subscribe('auth.authResponseChange', function(response) {
  
      if (response.status === 'connected') {
  
  //if connected open permissions dialog
  
         FB.login(function(response) {
  //if user grants permissions, make ajax call to pass signed request to php page
  
         if(response.status === 'connected'){
  
  
                 $.ajax({
          url : "http://xxxxxxio/bn/s_Request.php",
          type : 'POST',
          data: {signed_request: response.authResponse.signedRequest},
          success : function (result) {
  
             console.log(result);
          },
          error : function () {
             alert("error parsing signed request");
          }
        });//closes ajax 
  
              }else{
                  //if authorization cancelled, redirect to home page
  
                       window.location = "http://spilot.kd.io/bn/index.php";
  
                  }//closes else
  
   }, {scope: 'user_location,user_likes'});
  
        testAPI();
  
      } else if (response.status === 'not_authorized') {
        // the person is logged into Facebook, but not into the app
  
       FB.login(function(response) {
               // handle the response
   }, {scope: 'user_location,user_likes'});
  
      } else {
        //  the person is not logged into Facebook, call the login() 
  
        FB.login(function(response) {
               // handle the response
   }, {scope: 'user_location,user_likes'});
  
      }//closes else
  
    });//closes event subscribe
  
  var testAPI = function() {
      console.log('Welcome!  Fetching your information.... ');
      FB.api('/me', function(response) {
        console.log('Good to see you, ' + response.name + '.');
      });
    };
  </code></pre>