Send value to PHP via GET: responseText is EMPTY

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aleschenko
    New Member
    • Oct 2008
    • 3

    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="some text";
    echo $curimage;
    responseText is filled with "sometext" which is OK. What's the problem here ?
    My code is below:

    ------------------------------------file1.php-----------------------------------------------
    [CODE=php]<form action="#" method="get">
    <input type="button" onclick="showTe xt()" id="btnTxt" value="Show text" />
    <div id="item1"><?ph p require_once ("file2.php" ); $_GET['curval']='sometext';?></div>
    </form>

    <head>
    <script language="javas cript" type="text/javascript">

    var request = null;

    function createRequest()
    {
    // I use Firefox on Linux Fedora8
    request = new XMLHttpRequest( );
    }

    function printText()
    {
    if ( request.readySt ate == 4 && request.status == 200 )
    {
    alert(request.r esponseText);
    }
    }

    function showText()
    {
    createRequest() ;
    var url = "file2.php" ;
    request.open("G ET", url, true);
    request.onready statechange = printText;
    request.send(nu ll);

    }

    </script>
    </head>
    [/CODE]
    ------------------------------------file2.php-----------------------------------------------
    [CODE=php]<?php
    $curval = $_GET['curval'];
    echo $curval;
    ?>[/CODE]

    PLEASE HELP !!!
    THANK YOU!!!
    Last edited by gits; Oct 12 '08, 04:09 PM. Reason: added code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

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

    [CODE=javascript]var url = 'file2.php' + '?curval=' + your_curval;[/CODE]
    kind regards

    Comment

    • aleschenko
      New Member
      • Oct 2008
      • 3

      #3
      Originally posted by gits
      i don't see where you add the GET param to your url? it should look like:

      [CODE=javascript]var url = 'file2.php' + '?curval=' + your_curval;[/CODE]
      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.

      Comment

      • aleschenko
        New Member
        • Oct 2008
        • 3

        #4
        Send value via GET in PHP

        Hello, friends !
        Sorry for stupid post, I have a question about PHP.
        I have 2 PHP files and I want to send 'curval'="anyte xt" 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-----------------------------------------------

        Code:
        <form action="#" method="get"> 
        <input type="button" onclick="showText()" id="btnTxt" value="Show text" /> 
        <div id="item1"><?php require_once ("file2.php"); ?></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>
        ------------------------------------file2.php-----------------------------------------------
        [PHP]<?php
        $curval = $_GET['curval'];
        echo $curval;
        ?>
        [/PHP]


        Thank you a lot !
        Last edited by acoder; Oct 13 '08, 01:54 PM. Reason: Added [code] tags

        Comment

        • acoder
          Recognized Expert MVP
          • Nov 2006
          • 16032

          #5
          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.

          Comment

          Working...