• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

php 搞代码 3年前 (2022-01-25) 12次浏览 已收录 0个评论
文章目录[隐藏]
<code> function createXML(){                var xml = "";                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 + "" + 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);            }</code>

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

<code>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);            }</code>

回复内容:

<code> function createXML(){                var xml = "";                var options = document.getElementById("petTypes").childNodes;                var option = null;                for(va<span>@本文来*源gaodai#ma#com搞*!代#%^码$网*</span><textarea>搞gaodaima代码</textarea>r i = 0;i < options.length;i++){                    option = options[i];                    if(option.selected){                        xml = xml + "" + 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);            }</code>

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

<code>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);            }</code>

<code> xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); </code>

看着好像是多了个; ???

因为在传递过来的时候,传递的是字符串,这个时候PHP帮你自动转成了数组,但是后面get_file_contents(php://input)这个是读取的原始数据流,这个时候就需要你自己进行转了。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:javascript – php文件中执行print_r($_POST)时,显示Array(),为什么呢?
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址