开发者

Javascript asynchronous

开发者 https://www.devze.com 2023-01-20 21:51 出处:网络
I have some 3 methods. login(); isLogin(); reply(); function isLogin(){ FB.getLoginStatus(function(response) {

I have some 3 methods.

login();
isLogin();
reply();


function isLogin(){

 FB.getLoginStatus(function(response) {  
  if (response.session) {  
    // logged in and connected user, someone you know  
  } else {  
    // no user session available, someone you dont know  
  }  
 });  
}

function login (){  
  FB.login(function(response) {  
   if (response.session) {  
    // user successfully logged in  
   } else {  
    // user cancelled login  
  }  
 });  
}


function reply(){  
  var body = 'Reading Connect JS documentation';  
  FB.api('/me/feed', 'post', { body: body }, function(response) {  
  if (!response || response.error) {  
    alert('Error occured');  
  } else {  
    alert('Post ID: ' + response);  
  }  
 });  
}  

I need, when a user will want to reply a comment then reply method will execute. before executing reply method it should test if user is login, if user is not login then execute login method 开发者_运维知识库and call reply method again. How can I achieve this task

Thanks in advance


you need to construct conditions that will handle the following:

When a user will want to reply a comment

  1. Check session if user isLogin()
    • if TRUE then reply method is enabled by default
    • if FALSE then call login() method via ajax for awesomeness
      • if login.success then call reply method
      • if login.failed add statement here
0

精彩评论

暂无评论...
验证码 换一张
取 消