我有一个页面Practice.php和addtocart.php。我试图从Practice2.php发送多个数据到addtocart.php。但是我不知道如何分别检索多个数据。这是我的代码:>
practice2.php
function addtocart(price){
var productdetails=document.forms['mehendicones'].value;
var pcolor=document.getElementByClassName('mehendi_color').value;
var pquantity=document.getElementById('quantity_mehendi_color').value;
var bal=price*pquantity;
var ajax = new XMLHttpRequest();
ajax.open("POST","addtocart.php",true)
ajax.send(“ productdetails =” + productdetails +“&pcolor =” + pcolor +“&pquantity =” + pquantity +“&price =” + price +“&bal =” + bal);
ajax.onreadystatechange=function()
{
if(this.readyState==4 && this.status == 200){
alert(this.responseText);
}
}
}
addtocart.php
if(getenv('REQUEST_METHOD') == 'POST'){
$uname=file_get_contents("php://input");
$pdetails=//i dont know how to retrieve it seperately
}
答案 0 :(得分:1)
在请求中未包含Content-Type
标头来声明数据类型的情况下,请勿发布数据。
ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
然后PHP将能够解析它并为$_POST
填充数据,因此您不必从STDIN读取它。