Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ajax post to PHP

Status
Not open for further replies.

dougalim

Programmer
Mar 1, 2007
23
US
How can I post data from javascript using XMLHTTPRequest and then read the data in PHP. It works using POST with a form and hidden field but I want to send a large XML string without using a form and hidden field leaving the current page in the browser.

What value do I need to use for send
Code:
http.open("POST","abc.php",false);
http.send(?)

and how do I read the value in the php script?

 
I read the artice and I'm doing basically exactly what the article shows in the POST method section.

The problem i'm having is I do not appear to setting the $_POST[] values using http.send("var=value")

I'm expecting $_POST['var'] to have a value of "value" but it's not, is appears to be null.

if I use http.open("GET","abc.php?var=value",true)
then the $_GET['var'] = value

 
your question is for the javascript forum. it concerns how you encode and send variables with the POST method, using AJAX.

as a hint, have you tried setting the header properly
Code:
http.setRequestHeader("Content-type", "application/x-[URL unfurl="true"]www-form-urlencoded");[/URL]

the params should look like GET without the prepended ?. remember to escape your values before sending them up the pipe.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top