1

I have this html file that tries to call script2.php when the button is clicked:

<div id="wrapper">
        <a id="test" href="try.html" onclick="return false;">
            <input type="submit" id="gen" value="Generate!" onclick="dothis();"><br />
        </a>
        <script type="text/javascript">
            function dothis() {
                var url = document.getElementById("test").valueOf('href');
                alert(url);
                $("#quote p").load("script2.php");
            }
        </script>

        <div id="quote"><p></p></div>
    </div>

The script2.php has this in it, in which I try to get a text file from try.html:

<?php
  header("Cache-Control: no-cache");
  $file = 'test_put.txt';
  $url = "try.html";
  $current = file_get_contents($url);
  $current2 = strip_tags($current);
  file_put_contents($file, $current2);
  echo "Thanks for your response!";
?>

You see, the php file doesn't get the value of $url directly from the value of var url inside the javascript thing. While what I want is the $url value can vary in accordance with the var url.

I'd tried:

$url = "<script>document.write(url)</script>";

And this:

$url = "<script language ='javascript'>
          var url = document.getElementById('test').valueOf('href');
           document.write(url);
       </script>";

Then it twice said, failed to open stream.

I've googled and searched in SOF as well to address this problem, all I could find was the server-side and client-side thing that make this won't work simply. I found this too, but since I'm not doing such form I can't extract that solution into my problem.

Thanks..

1 Answer 1

2

I think you want something like this:

$("#quote p").load("script2.php?url=" + url);

That passes the URL in the query string. Then retrieve it in "script2.php":

$url = $_GET["url"];
Sign up to request clarification or add additional context in comments.

2 Comments

Oh thank you, you saved me. Hope you don't mind my asking, what does this mean? ?url=" + url?
@Safira it's the query string - that passes data to the server, which PHP can retrieve using $_GET[].

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.