PHP Do a POST in Javascript Page

Asked

Viewed 170 times

0

A Page PHP, need to pass via POST some parameters for an external page, until ai OK, but this external page has some commands Javascript.

When I send via cURL or FileGetContent, page loads, however the Javascript is not executed.

I tried to see Ajax, but it did not work due to the MVC structure of my Project.

Does anyone have any tips on how to call an external page via POST and make this page run Javascript her inline?

Down as I’m calling via Filegetcontent

    $url = "http://localhost/workspace/application/files/origin/oitprintteste.php";

    $content = http_build_query($data);

    $context = stream_context_create(array(
        'http' => array(
            'method'  => 'POST',
            'header'  => 'Content-Type: application/x-www-form-urlencoded',
            'content' => $content,
        )
    ));

      $teste = file_get_contents($url,true,$context);

Now an Example of What I Call Via Curl

    $url = "http://localhost/workspace/application/files/origin/oitprintteste.php";

    $content = http_build_query($data);

    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $content); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    $teste = curl_exec($ch);
  • Is there any way to post a line of code to analyze the situation? So it’s a little vague to understand your problem

  • I just added Samuel, I forgot...

  • Do you want to request through PHP at a url (serving html content) and want the js content on that page to run? That’s right?

  • That’s right @Tommelo

  • So that’s not gonna happen... The HTTP protocol works on text, requests, and replays return text (body, headers, etc.) following protocol standards. The person responsible for running a js script is the browser (there are other ways but this is the default scenario). Therefore, in your case, making a request through backend(PHP) the page script will not run.

  • Roger @Tommelo Thanks so much for the help, really I’m going to go for another strategy. Thank you

Show 1 more comment
No answers

Browser other questions tagged

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