php中学习Ajax时$_POST 取不到值?
showCities.php:<scripttype="text/javascript"language="javascript">varmyXmlHttpRequest...
showCities.php:
<script type="text/javascript" language="javascript">
var myXmlHttpRequest="";
function getXmlHttpObject(){
var xmlHttpRequest;
if(window.ActiveXobject){
xmlHttpRequest=new ActiveXobject("Microsofe.XMLHTTP");
}else{
xmlHttpRequest=new XMLHttpRequest();
}
return xmlHttpRequest;
}
function getCities(){
myXmlHttpRequest=getXmlHttpObject();
if(myXmlHttpRequest){
var url="/ajax/showCitiesPro.php";
var data="province="+$('sheng').value;
myXmlHttpRequest.open("post",url,true);
myXmlHttpRequest.setRequestHeader("Content-Type","applcation/x-www-form-urlencoded");
myXmlHttpRequest.onreadystatechange=chuli;
myXmlHttpRequest.send(data);
}
}
function chuli(){
if(myXmlHttpRequest.readyState==4){
if(myXmlHttpRequest.status==200){
window.alert(myXmlHttpRequest.responseXML);
}
}
}
function $(id){
return document.getElementById(id);
}
</script>
showCitiesPro.php:
<?php
header("Content-Type: text/xml;charset=utf-8");
$province=$_POST['province'];
echo "接收到数据是";
?>
window.alert(myXmlHttpRequest.responseXML);为null,这是为什么?
还有响应的显示
<br />
<b>Deprecated</b>: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in <b>Unknown</b> on line <b>0</b><br />
<b>Notice</b>: Undefined index: province in <b>E:\phpEnv\www\ajax\showCitiesPro.php</b> on line <b>7</b><br /> 展开
<script type="text/javascript" language="javascript">
var myXmlHttpRequest="";
function getXmlHttpObject(){
var xmlHttpRequest;
if(window.ActiveXobject){
xmlHttpRequest=new ActiveXobject("Microsofe.XMLHTTP");
}else{
xmlHttpRequest=new XMLHttpRequest();
}
return xmlHttpRequest;
}
function getCities(){
myXmlHttpRequest=getXmlHttpObject();
if(myXmlHttpRequest){
var url="/ajax/showCitiesPro.php";
var data="province="+$('sheng').value;
myXmlHttpRequest.open("post",url,true);
myXmlHttpRequest.setRequestHeader("Content-Type","applcation/x-www-form-urlencoded");
myXmlHttpRequest.onreadystatechange=chuli;
myXmlHttpRequest.send(data);
}
}
function chuli(){
if(myXmlHttpRequest.readyState==4){
if(myXmlHttpRequest.status==200){
window.alert(myXmlHttpRequest.responseXML);
}
}
}
function $(id){
return document.getElementById(id);
}
</script>
showCitiesPro.php:
<?php
header("Content-Type: text/xml;charset=utf-8");
$province=$_POST['province'];
echo "接收到数据是";
?>
window.alert(myXmlHttpRequest.responseXML);为null,这是为什么?
还有响应的显示
<br />
<b>Deprecated</b>: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in <b>Unknown</b> on line <b>0</b><br />
<b>Notice</b>: Undefined index: province in <b>E:\phpEnv\www\ajax\showCitiesPro.php</b> on line <b>7</b><br /> 展开
1个回答
2015-03-11 · 知道合伙人软件行家
百度网友ad45923b8
知道合伙人软件行家
向TA提问 私信TA
知道合伙人软件行家
采纳数:262
获赞数:386
从事IT互联网行业16年,经验丰富,擅长ASP、HTML、Javascript,Css,JQuery,PHP,PS,FL,AI,E,服务器等
向TA提问 私信TA
关注
展开全部
你也没有把$province的值输出啊,怎么就能确定没接收到值呢?
echo "接收到数据是"; 应该改成 echo "接收到数据是".$province;
echo "接收到数据是"; 应该改成 echo "接收到数据是".$province;
追问
如果得到值得话
window.alert(myXmlHttpRequest.responseXML)会输出XML对象
同时我也帮得到的数据放进log里
file_put_contents("e:/mylog.log",$province."\r\n",FILE_APPEND);
也没有出现值
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询