I would like to be able to read XMLHttpRequest that is sent to a PHP page. I am using prototype's Ajax.Request function, and I am sending a simple XML structure.
When trying to print the POST array on the PHP page, I don't get any output.
Any help appreciated.
EDIT: Below is my code
<html>
<head>
<SCRIPT type="text/javascript" src="prototype.js"></script>
</head>
<body>
<script type="text/javascript">
var xml='<?xml version=1.0 encoding=UTF-8?>';
xml=xml+'<notification>';
xml=xml+'heya there';
xml=xml+'</notification>';
xml=xml+'</xml>';
var myAjax = new Ajax.Request('http://localhost:8080/post2.php',{
contentType: 'text/xml',
parameters: xml,
method: 'post',
onSuccess: function(transport){ alert(transport.status); alert(transport.responseText); }
});
</script>
</body>
</html>
post2.php
Welcome <?php print_r($_POST); ?>!<br />
You will read it exactly the sme way you read normal request vars.
$_GET['varname'] and $_POST['varname']
php://input allows you to read raw POST data like
Welcome <?php print(file_get_contents('php://input')); ?>!<br />
Note: php://input is not available with enctype="multipart/form-data".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With