jayAnn
jayAnn

Reputation: 839

how to get the path of file_get_contents from a php file using javascript

is there a way to get/retrieve the value/parameters in a 'file_get_contents' in php file using javascript? my php code is...

<?php
  (file_get_contents("http://localhost/" . $_GET["path"] . "?json=" . urlencode($_GET["json"])));
?>

i want to display the value inside the 'file_get_contents' in my html using javascript. is there anybody here who could help me? please... thank you..

edit... how to show the xmlhttprequest in my html using javascript? thank you

Upvotes: 1

Views: 895

Answers (2)

RDL
RDL

Reputation: 7961

PHP is server side while Javascript is client side. The only way to get you parameters to js would be to return them via an array in an ajax call (ie. return as json) or echo the parameters to the final page where the js will hold them.

Upvotes: 3

jlmcdonald
jlmcdonald

Reputation: 13667

Because the file_get_contents function is processed on the server side before sending the response, there is no way for javascript to access the value of the argument. You could, however, use PHP to write additional HTML (or javascript) that's sent in the response; something like this:

  <?php
        echo "<script>var url='http://localhost/" . $_GET["path"] . "?json=" . urlencode($_GET["json"])."';</script>";
    ?>

You'd then have a javascript variable with that argument.

Upvotes: 2

Related Questions