Re: Parsing AJAX post data -- The Way

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 25-Jan-07, at 4:46 PM, Richard Lynch wrote:

On Thu, January 25, 2007 12:41 am, M5 wrote:
Just wondering what smart people do for parsing data sent by the
Javascript XMLHTTP object--e.g., http.send("post",url,true)...

In a normal form submit, the $_POST global nicely allocates form
elements as array elements automatically. But with the AJAX way, the
data get stuffed inside $HTTP_RAW_POST_DATA as a string, thereby
making extraction more tedious.

Call me crazy, but if AJAX is sending POST data correctly, your PHP
code shouldn't have to do anything special...

You're right in that "*IF* AJAX is sending POST data correctly" everything is okay--that is, will $_POST contain the posted data as array elements.

POST data is POST data.

The $HTTP_RAW_POST_DATA should be there as well, if you turned that
on, but that doesn't make $_POST go away.

Actually, that's not true. If the POST data is not set with the correct headers...

http.setRequestHeader('Content-Type', 'application/x-www-form- urlencoded');
http.setRequestHeader("Content-length", payload.length);
http.setRequestHeader("Connection", "close");

...then $_POST will be empty and the data that is sent can only be accessed from $HTTP_RAW_POST_DATA (which incidentally is off by default).

That was my problem--I wasn't sending those http headers. An earlier poster pointed it out to me, and that solved the problem.

...Rene

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux