473,395 Members | 2,446 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Send value to PHP via GET: responseText is EMPTY

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
4 7001
gits
5,390 Expert Mod 4TB
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
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
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
16,027 Expert Mod 8TB
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

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

Similar topics

1
by: Lakshmi Narayanan.R | last post by:
Hi Experts, In one SMS gateway project i need a great and urgent help from u all. There, the Service Providers sending the data thru "HTTP Headers" (For ex. sms-Id,sms-source ). So i need to...
0
by: Mpho Molahloe | last post by:
Hi, I'm trying to send (valid) XML using the function below and get an Access Denied Message on the line objXMLHTTP.send(xmldoc) when running the aspx on a Win2003 Server but the very same code...
2
by: Fatih BOY | last post by:
Hi, I want to send a report from a windows application to a web page like 'report.asp' Currently i can send it via post method with a context like local=En&Username=fatih&UserId=45&Firm=none...
3
by: keith.schincke | last post by:
I know I must be missing something basic. I am developing of Firefox 1.5 and am trying to to send a basic QUERY_STRING to a test CGI that will print the data back to the brower: I can print my...
1
by: mubarak basha | last post by:
hi, i wrote the following coding.......... <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Getting...
7
by: newlearner | last post by:
hi, On a test page i try to insert some values thru post method but the values which i send is not replaced in the url which i specify. I get the code found in the page and not the updated one. ...
2
by: ajaxcoder | last post by:
Hi In my project i had a login form and i am trying to send the username and password to the server for authentication using xmlHttpRequest. Hence i am using POST request but i am unable to send...
1
sid0404
by: sid0404 | last post by:
Hi I need to send data from my servlet to my html(which contains AJAX), so as per the motivation of the AJAX, this should be done without my webpage reloading / refresh. my code on the ajax...
1
by: toretto | last post by:
Hello, I have a script php that I use on my website to permit visitors to send me some email with some data, this is the html table code: <table width="730" border="0" cellpadding="0"...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.