Mis*_*saz 5 javascript php arrays ajax post
我正在尝试通过 AJAX 通过 POST 方法将数据发送到 php。PHP代码:
\n\n<?php\nprint_r($_POST);\nRun Code Online (Sandbox Code Playgroud)\n\nJavaScript 代码:
\n\nvar xml = new XMLHttpRequest();\nxml.open("POST", "test.php", false);\nxml.send("a=X");\ndocument.write(xml.responseText);\nRun Code Online (Sandbox Code Playgroud)\n\n结果是:
\n\nArray ( )\nRun Code Online (Sandbox Code Playgroud)\n\n为什么数组 [a] => "X" 中没有\xc2\xb4t?数组每次都是空的。我在 Apache 2.4.10 (XAMPP v3.2.1) 上使用 PHP 5.6.3。
\n您没有设置内容类型
var xml = new XMLHttpRequest();
xml.open("POST", "test.php", false);
xml.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xml.send("a=X");
Run Code Online (Sandbox Code Playgroud)