Reading data posted with XMLHttprequest

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Gaunt

    #1

    Reading data posted with XMLHttprequest

    I'm trying to post a form (using POST not GET) using the xmlHttpRequest
    object. I cannot work out how to get PHP (4.1.2) to read the data which
    I'm submitting. Everything works fine if I use GET I can just read it
    from $_GET. If I use POST nothing appears in $_POST.

    To try to use the POST method I'm encoding the fields into a URL
    encoded string and sending it as the parameter to the request.send()
    function from Javascript. /Something/ is going out because I can see it
    in the LiveHHTPHeaders extension to Firefox. Presumably it's being
    received by the server. But how on earth do I get at it!? Been driving
    me completely crazy.

    Help!

    --
    Pete
    ====
    *** Email is pete -at- dawnsun -dot- net
  • Janwillem Borleffs

    #2
    Re: Reading data posted with XMLHttprequest

    Peter Gaunt wrote:[color=blue]
    > To try to use the POST method I'm encoding the fields into a URL
    > encoded string and sending it as the parameter to the request.send()
    > function from Javascript. /Something/ is going out because I can see
    > it in the LiveHHTPHeaders extension to Firefox. Presumably it's being
    > received by the server. But how on earth do I get at it!? Been driving
    > me completely crazy.
    >[/color]

    I have never worked with XMLHttpRequest, but when the data is posted and the
    data doesn't show up in the $_POST array, it's probably sent as raw post
    data.

    To get this data, you should enable the always_populate _raw_post_data
    directive in your php.ini file, after which you should be able to receive
    the data through the $HTTP_RAW_POST_ DATA variable.


    JW



    Comment

    • Peter Gaunt

      #3
      Re: Reading data posted with XMLHttprequest

      Janwillem Borleffs wrote:
      [color=blue]
      > To get this data, you should enable the always_populate _raw_post_data
      > directive in your php.ini file, after which you should be able to receive
      > the data through the $HTTP_RAW_POST_ DATA variable.[/color]

      Thanks!

      Works a treat. I'd been hunting around all day for this information.

      --
      Pete
      ====
      *** Email is pete -at- dawnsun -dot- net

      Comment

      • y5

        #4
        re:Reading data posted with XMLHttprequest

        to use the $_POST global without enabling the raw data in php.ini, tr
        the following code

        objXMLHttpReque st.setRequestHe ader('Content-Type'
        'application/x-www-form-urlencoded')
        objXMLHttpReque st.send('var=va lue&var2=value2 ')

        ----
        http://eye.cc -php- web design

        Comment

        • R. Rajesh Jeba Anbiah

          #5
          Re: re:Reading data posted with XMLHttprequest

          y5 wrote:[color=blue]
          > to use the $_POST global without enabling the raw data in php.ini,[/color]
          try[color=blue]
          > the following code:
          >
          > objXMLHttpReque st.setRequestHe ader('Content-Type',
          > 'application/x-www-form-urlencoded');
          > objXMLHttpReque st.send('var=va lue&var2=value2 ');[/color]

          Or simply, file_get_conten ts('php://input');

          --
          <?php echo 'Just another PHP saint'; ?>
          Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

          Comment

          Working...