I faced the following error and I'm at a loss what to do with it.
I have PHP module in 2 files and JavaScript module. In PHP
part in File1.php I put some text to
$_GET['curimage']="img1.jpg";
and then read this text in File2.php
$curimage=$_GET['curimage'];
then I echo it
echo $curimage;
But on JavaScript part I receive EMPTY responseText ("").
And if in file2.php I don't read the text from $_GET, but assign it directly
$curimage="sometext";
echo $curimage;
responseText is filled with "sometext" which is OK. What's the problem here ?
My code is below:
------------------------------------file1.php-----------------------------------------------
Expand|Select|Wrap|Line Numbers
- <form action="#" method="get">
- <input type="button" onclick="showText()" id="btnTxt" value="Show text" />
- <div id="item1"><?php require_once ("file2.php"); $_GET['curval']='sometext';?></div>
- </form>
- <head>
- <script language="javascript" type="text/javascript">
- var request = null;
- function createRequest()
- {
- // I use Firefox on Linux Fedora8
- request = new XMLHttpRequest();
- }
- function printText()
- {
- if ( request.readyState == 4 && request.status == 200 )
- {
- alert(request.responseText);
- }
- }
- function showText()
- {
- createRequest();
- var url = "file2.php";
- request.open("GET", url, true);
- request.onreadystatechange = printText;
- request.send(null);
- }
- </script>
- </head>
Expand|Select|Wrap|Line Numbers
- <?php
- $curval = $_GET['curval'];
- echo $curval;
- ?>
THANK YOU!!!