By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,285 Members | 2,109 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,285 IT Pros & Developers. It's quick & easy.

Send value to PHP via GET: responseText is EMPTY

P: 3
Hello, friends,
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
  1. <form action="#" method="get">
  2. <input type="button" onclick="showText()" id="btnTxt" value="Show text" />
  3. <div id="item1"><?php require_once ("file2.php"); $_GET['curval']='sometext';?></div>
  4. </form>
  5.  
  6. <head>
  7. <script language="javascript" type="text/javascript">
  8.  
  9. var request = null;
  10.  
  11. function createRequest() 
  12. {
  13. // I use Firefox on Linux Fedora8
  14.     request = new XMLHttpRequest();
  15. }
  16.  
  17. function printText()
  18. {
  19.   if ( request.readyState == 4 && request.status == 200 )
  20.   {
  21.     alert(request.responseText);
  22.   }
  23. }
  24.  
  25. function showText()
  26. {
  27.   createRequest();
  28.   var url = "file2.php";
  29.   request.open("GET", url, true);
  30.   request.onreadystatechange = printText;
  31.   request.send(null);
  32.  
  33. }
  34.  
  35. </script>
  36. </head>
  37.  
------------------------------------file2.php-----------------------------------------------
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $curval = $_GET['curval'];
  3. echo $curval;
  4. ?>
PLEASE HELP !!!
THANK YOU!!!
Oct 12 '08 #1
Share this Question
Share on Google+
4 Replies


gits
Expert Mod 5K+
P: 5,333
i don't see where you add the GET param to your url? it should look like:

Expand|Select|Wrap|Line Numbers
  1. var url = 'file2.php' + '?curval=' + your_curval;
kind regards
Oct 12 '08 #2

P: 3
i don't see where you add the GET param to your url? it should look like:

Expand|Select|Wrap|Line Numbers
  1. var url = 'file2.php' + '?curval=' + your_curval;
kind regards
Hello, dear gits !
Thank you very much 4 your reply, actually I'm new with Ajax,
I though the statement like $_GET['curval']='sometext' will be enough to send 'sometext' to file2.php
Can you please edit my code and show how it should look like ?
I will appriciate your help, a lot of thanks !!!

Andrey.
Oct 12 '08 #3

P: 3
Hello, friends !
Sorry for stupid post, I have a question about PHP.
I have 2 PHP files and I want to send 'curval'="anytext" from from file1.php to file2.php via GET. The url is http://localhost/file2.php?curval=anytext
What function I should use to send this value to file2.php ? Can anyone edit my text below to implement this solution ? A lot of thanks !!!

Here's my code:

------------------------------------file1.php-----------------------------------------------

Expand|Select|Wrap|Line Numbers
  1. <form action="#" method="get"> 
  2. <input type="button" onclick="showText()" id="btnTxt" value="Show text" /> 
  3. <div id="item1"><?php require_once ("file2.php"); ?></div> 
  4. </form> 
  5.  
  6. <head> 
  7. <script language="javascript" type="text/javascript"> 
  8.  
  9. var request = null; 
  10.  
  11. function createRequest()  
  12. // I use Firefox on Linux Fedora8 
  13.     request = new XMLHttpRequest(); 
  14.  
  15. function printText() 
  16.   if ( request.readyState == 4 && request.status == 200 ) 
  17.   { 
  18.     alert(request.responseText); 
  19.   } 
  20.  
  21. function showText() 
  22.   createRequest(); 
  23.   var url = "file2.php"; 
  24.   request.open("GET", url, true); 
  25.   request.onreadystatechange = printText; 
  26.   request.send(null); 
  27.  
  28.  
  29. </script> 
  30. </head> 
  31.  
------------------------------------file2.php-----------------------------------------------
[PHP]<?php
$curval = $_GET['curval'];
echo $curval;
?>
[/PHP]


Thank you a lot !
Oct 13 '08 #4

acoder
Expert Mod 15k+
P: 16,027
Threads merged. Please do not double post your questions.

Also remember to use code tags when posting code. See How to ask a question. Thanks!

Moderator.

Re. your problem: gits has already provided a solution. See an Ajax example.
Oct 13 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.