473,396 Members | 1,933 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,396 software developers and data experts.

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
Jul 17 '05 #1
4 4412
Peter Gaunt wrote:
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.


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

Jul 17 '05 #2
Janwillem Borleffs wrote:
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.


Thanks!

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

--
Pete
====
*** Email is pete -at- dawnsun -dot- net
Jul 17 '05 #3
y5
to use the $_POST global without enabling the raw data in php.ini, tr
the following code

objXMLHttpRequest.setRequestHeader('Content-Type'
'application/x-www-form-urlencoded')
objXMLHttpRequest.send('var=value&var2=value2')

----
http://eye.cc -php- web design
Jul 17 '05 #4
y5 wrote:
to use the $_POST global without enabling the raw data in php.ini, try the following code:

objXMLHttpRequest.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded');
objXMLHttpRequest.send('var=value&var2=value2');


Or simply, file_get_contents('php://input');

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

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: news.west.cox.net | last post by:
Forgive me, I am new to javascript ( about 1 week playing with it ). I am proficient in C, perl, python, java, etc... but no javascript. I wrote an applet about 1 million years ago that has...
0
by: adamsbarker | last post by:
i have the following javascript code: --------- try{F=new ActiveXObject("Msxml2.XMLHTTP")} catch(e) { try{F=new ActiveXObject("Microsoft.XMLHTTP")} catch(e){F=typeof...
4
by: J.D. | last post by:
Hello, I am working on a client project and they have a connection to a catalog system that passes data back and forth as xml over http The format of the data is as follow(s) > <?xml...
1
by: 4levels | last post by:
Dear Folks, I stumbled upon a strange behaviour of the XMLHttpRequest.. Maybe I'm just not well informed enough about its possibilities, so could someone please confirm my question? When I...
9
by: ananttickoo | last post by:
hey !! .. i am new to thsi lang... i wanted to know how to read a file .. at remort location eg .. suppose a file http://www.url.com/update.txt is at a site and i am generating a page from...
1
by: Tarik Monem | last post by:
OK, I'm pretty sure this cannot work because I'm trying to use JavaScript (client-side) to write to an xml file (which is server-side) using XMLHttpRequest. Can I use PHP do what I'm trying to do?...
2
by: Wizfrog | last post by:
Hello, I'm working with a pretty large XML file, but I really only need to display a few things that requires quite a few transforms. I already limited to the transforms to the data i need to...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.