English 中文(简体)
Facebook Ajax.post fails after calling Facebook.showPermissionDialog
原标题:

I have a situation where I call Facebook.showPermissionDialog( offline_access ...) then later I make an ajax.post call. The ajax.post call fails if the call to the permission dialog was made prior. But it succeeds when the permission dialog was not called prior. Is anyone aware of some relationship between this dialog and ajax.post?

If you want to check out the problem firsthand, visit my app at http://apps.facebook.com/rails_dev (THIS IS A FACEBOOK APP SO YOU MUST GRANT ACCESS TO YOUR PROFILE).

Here s the code that calls Facebook.showPermissionDialog():

<?php
  echo $this->jsInit($config);
  if(!$userNamespace->newGame) {
$log->debug( NOT new game, calling turnResume() );
    echo  setVarBalance(  . $this->gamePlayerData[ funds ] .  ); ."
";
    echo  turnResume(); ."
";
  }
  echo $this->drawTrack($this->routeData, $this->trainData);
  echo $this->drawCityGoods($this->cityGoodsData);
  //$link =  startSetCity() ; //$config->url->absolute->fb->canvas .  /turn/start-set-city ;
  echo $this->drawCitiesAjax($this->cityDescData);
$log->debug( view: end start-select-city );

  if(!$facebook->api_client->users_hasAppPermission( offline_access , $this->fbUserId)):
?>
  var dialog = new Dialog().showMessage( Constant Authorization ,  Rails Across Europe is about to request  Constant Authorization  to your account. If you don t give us constant authorization, Facebook will eventually cause your game to timeout, thereby losing all game information. By granting this authorization, Facebook will not cause your game to timeout. This is the only reason we need this authorization. );
  dialog.onconfirm = function() {
    Facebook.showPermissionDialog( offline_access , null, false, null);
  }
<?php
  endif;
?>[

Here s the FBJS code that calls ajax.post:

    switch(state) {
      case START_SET_CITY:
//new Dialog().showMessage( test ,  START_SET_CITY );
//console.time( start_set_city );
        ajax.responseType = Ajax.JSON;
        ajax.ondone = function(data) {
//console.time( ondone );
//new Dialog().showMessage( in ajaxSetCity.ondone );
//new Dialog().showMessage( test ,  city=  + dump(data.city, 3) +  ::: train=  + dump(data.train, 3));
          drawCityAjax(data.city, data.train);
          setVarBalance(data.funds);
          ajax.responseType = Ajax.JSON;
          ajax.post(baseURL +  /turn/start );
//console.timeEnd( ondone );
        };
        ajax.post(baseURL +  /turn/start-set-city , param); // <=== THIS IS THE AJAX CALL THAT FAILS
        var actionPrompt = document.getElementById( action-prompt );
        var innerHtml =  <span><div id="action-text">Build Track: Select a city where track building should begin</div> +
                         <div id="action-end"> +
                         <input type="button" value="End Track Building" id="next-phase" onClick="moveTrainAuto();" /> +
                         </div></span> ;
        actionPrompt.setInnerXHTML(innerHtml);
        var btn = document.getElementById( next-phase );
        btn.addEventListener( click , moveTrainAutoEvent);
        state = TRACK_CITY_START;
//console.timeEnd( start_set_city );
        // get funds balance from backend and call setVarBalance()
        break;
问题回答

I had the same problem if ajax.requireLogin parameter was true. Since you are already asking for extended permissions you can set it to false. Code below works for me:

Facebook.showPermissionDialog("publish_stream", function(permissions) {

    var form_data = form.serialize();

    var ajax = new Ajax();
    ajax.responseType = Ajax.RAW;
    ajax.requireLogin = false;
    ajax.ondone = function(data) {
        console.log("onerror")            
    };
    ajax.onerror = function() {            
        console.log("onerror")            
    };

    ajax.post("http://foo.example.com/submit", form_data);

    return false;
});




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签