1

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

5
  • Nice, I've been wondering how to do this +1 if you do anwser please post how to seperate the path with explode() +1 Commented Mar 16, 2011 at 5:51
  • PHP do not have js engine to run js code. And requesting data from your own server is quite nonsense Commented Mar 16, 2011 at 5:51
  • You're trying to retrieve information from a file on your server and then displaying that returned information on the page - using JavaScript? Commented Mar 16, 2011 at 5:59
  • no, not the returned information, but the url page...or the xmlhttprequest or whatever it is.. it is something like localhost/jquerystudy/mine/processjson.php?path=masterData/…} Commented Mar 16, 2011 at 6:28
  • let me rephrase my question. how to show the xmlhttprequest in my html? Commented Mar 16, 2011 at 7:24

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

echo the parameters to the final page?... i already tried that one but the output is in complete. it will not display "localhost....". instead, it will only display the "processjson.php?path=masterData/...."
something like: echo "<script>var url = '$url';</script>"; where $url is the php version of the url. Then you can access it in your js using the url variable.
ok, thank you for that one. i will just update if it will works. thanks a lot
2

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.

1 Comment

i just try that one and it didn't work the way i want it to be.. it also doesn't display the data. but thank you for the help. :) i want to display something like.... localhost/jquerystudy/mine/processjson.php?path=masterData/…{%22SessionID%22:%226nj7pElV4G2zn8pi55atXu3Gj67d7zp....main_account_group_desc%22}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.