Pass code via url with/to a java script (php+codeigniter)

Asked

Viewed 201 times

0

Hi, I have the following case. I have a part with just a few data from various locations, I would like to do something to open a pop-up to show all the data from that location, for that would need to pass the id of the same to the url to do the select. Method where I am

foreach ($dadosLocais as $row) {
  $marker = array();
  $marker['position'] = $row->latitude . ',' . $row->longitude;
  $marker['title'] = $row->nome_nascente;
  $dadosUsuario = $this->Usuario_model->getUsuario()->row();
  $marker['infowindow_content'] = '<h2>' . $row->nome_nascente . '</h2>' . 'Descrição: '
  . $row->descricao_nascente . '</br>' . 'Latitude: ' . $row->latitude
  . '</br>' . 'Longitude: ' . $row->longitude
  . '</br>' . 'Usuário que Cadastrou: ' . $dadosUsuario->nome
  .'</br>' . 'Imagem: ' . '<a href="javascript:abrir(500,200)"> Visualizar Imagem</a>'; }

Already my java script is:

    <script languague="javascript">
  function abrir(largura, altura){ window.open('<?= site_url('Nascente/verImagem') ?>','popup','width='+largura+',height='+altura+',scrolling=auto,top=0,left=0') }
</script>

The pop-up is opening correctly, I just don’t know how to pass the id_local that is in the forearch to the java script.

1 answer

0


I imagine it’s going to be something like this. I assumed that the $row->ID_LOCAL is in the $row, see if that’s right. And I changed the order of the parameters by first passing the ID to the popup function, and then the largura, altura. If you prefer otherwise, just change the order.

foreach ($dadosLocais as $row) {
  $marker = array();
  $marker['position'] = $row->latitude . ',' . $row->longitude;
  $marker['title'] = $row->nome_nascente;
  $dadosUsuario = $this->Usuario_model->getUsuario()->row();
  $marker['infowindow_content'] = '<h2>' . $row->nome_nascente . '</h2>' . 'Descrição: '
  . $row->descricao_nascente . '</br>' . 'Latitude: ' . $row->latitude
  . '</br>' . 'Longitude: ' . $row->longitude
  . '</br>' . 'Usuário que Cadastrou: ' . $dadosUsuario->nome
  .'</br>' . 'Imagem: ' . '<a href="javascript:abrir(' . $row->ID_LOCAL . ',500,200)"> Visualizar Imagem</a>'; 

}

I don’t know the function site_url from your framework, maybe it already has the option to pass querystring parameters. If you have, use this and do not do this concatenation that I did below:

<script languague="javascript">
    function abrir(idLocal, largura, altura) { 
        window.open('<?= site_url('Nascente/verImagem') ?>?idLocal=' + idLocal, 'popup', 'width='+largura+',height='+altura+',scrolling=auto,top=0,left=0');
    }
</script>

Browser other questions tagged

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