How to send a parameter through an iframe to a page on another server?

Asked

Viewed 50 times

-1

I need a help I have a page on an X server and I need to get another page from the Y server. I tried on ajax and I couldn’t so I had to use the iframe, but I need to pass a parameter to the destination page of the Y server and it is not working?

Below follow the codes:

Source X Server Page

<?php
    error_reporting(0);
    ini_set("display_errors", 0 );
    session_start();

    $perfil = $_SESSION['perfil'];
    echo $perfil;
?>
<br>
<iframe 
    style="border: 0;"
    src="https://172.20.220.50/webservice/listaRetorno.php?perfil=teste"
    width="100%"
    height="100%"
    frameborder="0"
    scrolling="no">
</iframe>

Y server page that returns in the above code iframe:

// $perfil = $_POST['perfil'];  
$perfil = $_GET['perfil'];  
echo $perfil;
  • Take a look here: https://developer.mozilla.org/pt-PT/docs/Web/API/Window/postMessage

1 answer

0

Probably you will need synchronous responses, so it is best to make the conversation between the two applications through a protocol (ajax preference) with typed return (for example json).

Because Voce could not for example make a simple $.post('other server') and catch the result ?

  • he probably didn’t get it with ajax because of the Cors, which is a security issue.

  • still there should be better possibilities than an iframe, of course, depending on the level of capacity of changes it has on the server

  • I did not say there is, even via Ajax if solving the Cors will work, I just answer your question "Because Voce could not for example make a simple" with a probability. Being different servers the problem is usually Cors, so the server you tried to access should allow this.

Browser other questions tagged

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