开发者社区> 问答> 正文

php文件中执行print_r($_POST)时,显示Array(),为什么呢?

 function createXML(){
                var xml = "<pets>";
                var options = document.getElementById("petTypes").childNodes;
                var option = null;
                for(var i = 0;i < options.length;i++){
                    option = options[i];
                    if(option.selected){
                        xml = xml + "<type>" + option.value + "<\/type>";
                    }
                }
                xml = xml + "<\/pets>";
                return xml;
            }
            
            function sendPetTypes(){
                createXMLHttpRequest();
                var xml = createXML();
                var url = "PostingXMLExample.php?timeStamp=" + new Date().getTime();
                
                xmlHttp.open("POST",url,true);
                xmlHttp.onreadystatechange = handleStateChange;
                xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
                xmlHttp.send(xml);
            }

php文件中执行print_r($_POST)时,显示Array(),当执行echo file_get_contents("php://input")时,显示内容,为什么呢?请大神赐教

function handleStateChange(){
                if(xmlHttp.readyState == 4){
                    if(xmlHttp.status == 200){
                        parseResults();
                    }
                }
            }
            
            function parseResults(){
                var responseDiv = document.getElementById("serverResponse");
                if(responseDiv.hasChildNodes()){
                    responseDiv.removeChild(responseDiv.childNodes[0]);
                }
                var responseText = document.createTextNode(xmlHttp.responseText);
                responseDiv.appendChild(responseText);
            }

展开
收起
星球华人 2016-04-09 16:05:07 3749 0
1 条回答
写回答
取消 提交回答
  • 你可以使用var_dump($_POST);

    2019-07-17 18:40:12
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
PHP安全开发:从白帽角度做安全 立即下载
PHP 2017.北京 全球开发者大会——高可用的PHP 立即下载
复杂PHP系统性能瓶颈排查及优化 立即下载