When calling an iframe inside a . php file, how to send a variable and receive it on the page pulled by the iframe?

Asked

Viewed 2,495 times

0

I have an index.php page that contains the following script:

<html>

//cabeçalho...

<div id="conteudo"> 
</div>


<script type="text/javascript">


$(this).on('load',function(){

    var dadosLink = 'nada';
    var mercado = 'nada';
    $.ajax({

        url:'conteudo.php',
        method: 'POST',
        data:{ dados:dadosLink,
                mercado:mercado
                 },
        success: function(data)
            {

            $("#conteudo").html(data);

            }, 

            error: function(data)

            {
            $("#conteudo").html(data);
                }

    });

    });


</html>

  </script>

This page sends the variable data dadLink and marketplace for the content file.php

Follow the content.php file:

<?php require_once('Connections/Gymo.php'); 

$aba = $_POST['dados'];
$mercado = $_POST['mercado'];

if  ($aba == "nada"){
echo '

<IFRAME name=Destaques src="mercadoria.php" frameBorder=0 style="overflow: scroll; height: 100vh; width: 100vw;"  scrolling=no>
<div align="center"></div>
</IFRAME>


';}

And then the.php content takes the content from the.php merchandise page and sends it to the "content" div of the index.php page.

Follow my attempt at merchandise.php:

<?php
    //Incluir a conexão com banco de dados
    include_once('Connections/Gymo.php');

    //Recuperar o valor da palavra
    $setor = "alimento";
    $mercado= "dia";
    $mercado=$mercado;
    //Pesquisar no banco de dados nome do curso referente a palavra digitada pelo usuário
    $id= "SELECT id FROM $mercado";
    $setor = "
    SELECT * FROM banco_fotos
  INNER JOIN $mercado ON `$mercado`.`id` = `banco_fotos`.`id` 
  where banco_fotos.setor like '%$setor%'

    ";

    $resultado_setor = mysql_query($setor, $Gymo);

        while($rows = mysql_fetch_assoc($resultado_setor)){

            echo''.$rows['descrp'].''.$rows['de'].''.$rows['por'].;} ?>

Finally, the doubt:

How do I get the merchandise page.php to receive the variables that are declared in the content.php ($market and $tab)?

Because the browser informs every time that the variables $sector and $merchandise market.php are not declared!

I’ve been trying so hard to find this solution for days, but I can’t!

I also tried to use this iframe in the.php content, to try to recover the id and name attribute in the.php merchandise, but I couldn’t do it either:

<IFRAME name=Destaques src="mercadoria.php" id="'.$aba.'" name="'. $mercado .'""frameBorder=0 style="overflow: scroll; height: 100vh; width: 100vw;"  scrolling=no>
<div align="center"></div>
</IFRAME>

There is a solution to this?

  • 1

    To make this exchange of information between iframe and the parent page, it must be in javascript or jquery.

  • Thank you for the comment. Could you tell me how this is done, or where I can find out how to do it? Please

1 answer

1


Go through the GET method src=\"mercadoria.php?dados=".$aba."&mercado=".$mercado."\

if  ($aba == "nada"){
echo "

<IFRAME name=Destaques frameBorder=0 style=\"overflow: scroll; height: 100vh; width: 100vw;\"  scrolling=no src=\"mercadoria.php?dados=".$aba."&mercado=".$mercado."\" >
<div align=\"center\"></div>
</IFRAME>


";}

Merchandise page

$aba = $_GET['dados'];
$mercado = $_GET['mercado'];
  • 1

    The example is given in the answer. They pass the value of their variables through the URL src=\"mercadoria.php?dados=".$aba."&mercado=".$mercado."\

  • It really worked! Thank you very much! I’ve been racking my brain for so long!

  • Taking advantage of the post: there is a way for me to use this src to send the php variable to php during a include?

  • @Guilhermesilvadeoliveira honestly could not understand the scenario of this new situation of include, maybe a new question with this new scenario would be more enlightening

Browser other questions tagged

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