Reputation: 31
I have problems in receiving POST request in PHP. I'm using JavaScript to send data to a PHP page with POST request. The JavaScript is from OpenLayers.js, and the part that sends the request looks like this:
var postrequest = OpenLayers.Request.POST({
url: "http://localhost/index.php",
data: "success",
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
});
In PHP, I'm using this code to see, what I'm getting:
<?php
print_r($_POST);
?>
This is what happens:
So the data is sent and received, but my PHP code doesn't somehow understand it, or I'm not using the right PHP function.
Any suggestions, where to look, and what to try?
Upvotes: 2
Views: 2728
Reputation: 1
I guess you need include XMLHttpRequest.js library, you can download it from this link
https://github.com/ilinsky/xmlhttprequest
Upvotes: 0
Reputation: 22247
I think the "data" property needs to be an object containing key/value pairs.
eg:
var postrequest = OpenLayers.Request.POST({
url: "http://localhost/index.php",
data: {
userName: "myUsername",
password: "myPassword"
},
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
});
If this works when you print_r($_POST) you should see array("userName" => "myUsername", "password" => "myPassword")
Upvotes: 5