我正在尝试使用 XMLHttpRequest 从 file://example.html 到http://localhost/index.php发出请求。我读了很多关于 CORS(在这种情况下,origin 为 null,这是可以的。)我不知道我做错了什么。我的请求完成得很好,但 $_POST 是空的!除非我设置了“内容类型:应用程序/x-www-form-urlencoded”。但是“text/plain”或“application/json”在 $_POST 中没有结果......为什么?
xhr.open("POST", "http://localhost/index.php", true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = handler;
xhr.send({'a':'12'});
Run Code Online (Sandbox Code Playgroud)