window.open is not working after running Ajax

Asked

Viewed 47 times

0

I am developing a URL sharing system saving in database every time it is clicked on one of the social networks of the site.

It turns out that the window.open what use to access the social network is not working after the Ajax call.

Does anyone have any idea why this happens?

An example of the sharing link:

teste.com.br/teste?c=xyoz&cc=1

the cc=1 is the lastInsertId(); when you save the share.

HTML:

<a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo rawurlencode($url."&c=cd3a0725fa81899"); ?>" class="popup" title="Compartilhe com Facebook" rede-social="facebook">
  <span class="icon">
    <svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="18px" height="18px" viewBox="0 0 28 28" enable-background="new 0 0 28 28" xml:space="preserve">
      <path d="M27.825,4.783c0-2.427-2.182-4.608-4.608-4.608H4.783c-2.422,0-4.608,2.182-4.608,4.608v18.434
            c0,2.427,2.181,4.608,4.608,4.608H14V17.379h-3.379v-4.608H14v-1.795c0-3.089,2.335-5.885,5.192-5.885h3.718v4.608h-3.726
            c-0.408,0-0.884,0.492-0.884,1.236v1.836h4.609v4.608h-4.609v10.446h4.916c2.422,0,4.608-2.188,4.608-4.608V4.783z" />
    </svg>
  </span>
  <span class="text">Facebook</span>
</a>

JS:

$('.rrssb-buttons li a').click(function(){
  var url        = "ajax/salvarCompartilhamento.php";
  var redesocial = $(this).attr('rede-social');
  $.ajax({
    type:  'post',
    data:  {
            'rede_social' : redesocial,
           },
    url:   url,
    cache: false,
    dataType: 'html',
    timeout:  120000,
    async:false,
    success: function(link){
      if(link != 'erro'){
        sucesso = true;
      }
    }
  });
  if(sucesso){
    var t = 600;
    var i = 450;
    var h = ($(window).width()-t)/2;
    var n = ($(window).height()-i)/2;
    var o = $(this).attr('href') + link;
    var w = "status=1,width="+t+",height="+i+",top="+n+",left="+h;
    window.open(o,"share",w);
  }
});

PHP:

include_once '../includes/constantes.php';
include_once __CLASS_FOLDER__.'/Teste.class.php';

if(!empty($_POST)){
  $dados = $_POST;
} else if(!empty($_GET)) {
  $dados = $_GET;
} else {
  die('Acesso não autorizado');
}

$teste = new Teste();
$salvado = $teste->salvarCompartilhamento($dados);

if(is_numeric($salvado)){
  echo "&ss=$salvado";
} else {
  echo 'erro';
}
  • Are you aware of what an asynchronous call, which is AJAX, means in practice?

  • Yes, in practice, if would be executed before the end of ajax. But the async:false flag would not disable this?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.