小编Joh*_*ohn的帖子

CORS:无法获取 POST 请求正文。

我正在尝试使用 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)

javascript php cors

1
推荐指数
1
解决办法
3616
查看次数

标签 统计

cors ×1

javascript ×1

php ×1